Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: option to specify which handlers to use #296

Open
pietdaniel opened this issue Feb 16, 2015 · 3 comments
Open

Feature Request: option to specify which handlers to use #296

pietdaniel opened this issue Feb 16, 2015 · 3 comments

Comments

@pietdaniel
Copy link

Handlers and Needed Use Case

A lot of the handlers are amazing but without the ability to fine tune which handlers I want to use I am unable to use this library for my use case. I only care for the date specific handlers to be active such that the following,

Chronic.parse("17 april 89")  => 1969-04-17 12:00:00 -0500

will parse as expected. Except I wish to turn of the 'simple' and 'complex' handlers such that:

Chronic.parse("tomorrow") => nil

Possible implementation

This could be done through the option interface, either via definitions

Chronic.parse("tomorrow", :definitions => :date)

or view handler specification

Chronic.parse("tomorrow", :handlers => [:handle_m_d])
@davispuh
Copy link
Collaborator

I've been thinking about such feature for next version as I also find this needed and useful, but I haven't decided yet about best implementation.

@pietdaniel
Copy link
Author

At the moment I've constructed this monkey patch

   def self.get_parser
     # need to monkey patch out the unneccessary parse definitions
     definition_grabber = Chronic::Parser.new
     new_definitions = {}
     new_definitions[:date] = definition_grabber.definitions[:date]
     new_definitions[:endian] = definition_grabber.definitions[:endian]
     new_definitions[:anchor] = {}
     new_definitions[:arrow] = {}
     new_definitions[:narrow] = {}
     new_definitions[:time] = {}

     Chronic::Parser.send(:define_method, "definitions") do |*options|
       new_definitions
     end

     Chronic::Parser.new
   end

but knowing that the feature is needed I will probably submit a PR. The approach I foresee implementing is allowing the definitions method to grab definitions from SpanDictionary based upon flags set within the options variable. Something like

Chronic.parse("tomorrow", :definitions => [:date, :endian])

which would provide results similar to the monkey patch

EDIT: (did not mean to close this issue)

@davispuh
Copy link
Collaborator

I don't recommend working much on current master branch because those changes will have to be reworked for next version, I've rewrite branch in progress, see #278 and definitions are changed quite radically there... but if you need this change soon then just go for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants