mojombo/chronic — pull request #236 by TalkativeTree (2013-12-11 02:14:29+00:00)
Title: Refactor/parser#definitions

I extracted the @@definitions global variable into Dictionary and Definitions subclasses seen in dictionary.rb and definition.rb. All tests passing.

Instead of being defined in Parser#definitions, it now is:
```ruby
def definitions(options = {})
SpanDictionary.new(options).definitions
end
```
Parser#definitions returns still returns a hash of all of the definitions and there were no changes made to Parser#tokens_to_span.

Now to add a new definiton, we would have to just add it to SpanDictionary's @defined_items
```ruby
def initialize(options = {})
super
@defined_items = [:time,:date,:anchor,:arrow,:narrow,:endian]
end
```

and created a new subclass of SpanDefinitions. Here is an example of :narrow definitions converted over

```ruby
class NarrowDefinitions < SpanDefinitions
class << self
def definitions(options={})
[
Handler.new([:ordinal, :repeater, :separator_in, :repeater], :handle_o_r_s_r),
Handler.new([:ordinal, :repeater, :grabber, :repeater], :handle_o_r_g_r)
]
end
end
end
```

One thing to look at might be the greater amount of require files and includes I am using.

A side note, I used the class << self method used in the rest of the code, but is there a reason Chronic doesn't just used self.method? It's shorted than wrapping methods in class << self and less ends and the end make it easier to read.