From: Gordon Thiesfeld Date: 2010-08-13T07:05:30+09:00 Subject: Re: Highline and Chronic --0015174be75e2bd38f048da78fdd Content-Type: text/plain; charset=ISO-8859-1 On Thu, Aug 12, 2010 at 2:42 AM, R.. Kumar 1.9.1 OSX 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 --0015174be75e2bd38f048da78fdd--