From: R.. Kumar 1.9.1 OSX on 12 Aug 2010 03:42 I just heard of Chronic and wanted to integrate it with Highline so i could get natural language dates like "yesterday", "tomorrow" etc. I find that I get a nil returned if I do: dob1 = ask("DOB? ", Chronic) However, if i try this it works: class NameClass def self.parse( string ) Chronic.parse(string) end end dob = ask("Date? ", NameClass) Looking thru source reveals that : elsif [Date, DateTime].include?(@answer_type) or @answer_type.is_a?(Class) @answer_type.parse(answer_string) Now Chronic is a module not a class. So i guess in this case no part of the "case" was called. Now my question is: 1. Should there be a respond_to in the Highline case, or perhaps a check for module also ? 2. Is there anyway i can do this in one line without modifying highline, and without creating a separate class. Is there some block method or param i could use to invoke Chronic.parse ? thanks. -- Posted via http://www.ruby-forum.com/.
From: Gordon Thiesfeld on 12 Aug 2010 18:05 [Note: parts of this message were removed to make it a legal post.] On Thu, Aug 12, 2010 at 2:42 AM, R.. Kumar 1.9.1 OSX <sentinel1879(a)gmail.com > wrote: > I just heard of Chronic and wanted to integrate it with Highline so i > could get natural language dates like "yesterday", "tomorrow" etc. > > I find that I get a nil returned if I do: > > dob1 = ask("DOB? ", Chronic) > > However, if i try this it works: > > class NameClass > def self.parse( string ) > Chronic.parse(string) > end > > end > > dob = ask("Date? ", NameClass) > > Looking thru source reveals that : > > elsif [Date, DateTime].include?(@answer_type) or > @answer_type.is_a?(Class) > @answer_type.parse(answer_string) > > Now Chronic is a module not a class. So i guess in this case no part of > the "case" was called. > Now my question is: > 1. Should there be a respond_to in the Highline case, or perhaps a check > for module also ? > > 2. Is there anyway i can do this in one line without modifying highline, > and without creating a separate class. Is there some block method or > param i could use to invoke Chronic.parse ? > > You could use a proc object # test.rb require 'rubygems' require 'highline' require 'chronic' hl = HighLine.new dob1 = hl.ask("DOB? ", proc{|x| Chronic.parse(x)} ) p dob1 ####### >ruby test.rb DOB? Last Tuesday Tue Aug 10 12:00:00 -0500 2010
From: James Edward Gray II on 12 Aug 2010 20:19 On Aug 12, 2010, at 2:42 AM, R.. Kumar 1.9.1 OSX wrote: > 1. Should there be a respond_to in the Highline case, or perhaps a check > for module also ? That may be a better approach. If you have the time, fork the project on Github and work out a patch for it so we can see how that looks. James Edward Gray II
|
Pages: 1 Prev: Multithreading problem Next: [ANN] Jquery_rails3 1.4.2 beta1 released |