Highline and Chronic

  • Thread starter R.. Kumar 1.9.1 OSX
  • Start date
R

R.. Kumar 1.9.1 OSX

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.
 
G

Gordon Thiesfeld

[Note: parts of this message were removed to make it a legal post.]

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
 
J

James Edward Gray II

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=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

HighLine Questions 5
[SUMMARY] HighLine (#29) 0
[ANN] Chronic-0.1.0 13
[Highline] Custom validation 2
[QUIZ] HighLine (#29) 8
[ANN] HighLine 0.5.0 7
[SOLUTION] HighLine (#29) 6
[ANN] HighLine 0.6.0 -- Now with menus! 15

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top