Class | Chronic::Parser |
In: |
lib/chronic/parser.rb
|
Parent: | Object |
DEFAULT_OPTIONS | = | { :context => :future, :now => nil, :guess => true, :ambiguous_time_range => 6, :endian_precedence => [:middle, :little], :ambiguous_year_future_bias => 50 | Hash of default configuration options. |
now | [RW] | |
options | [R] |
options - An optional Hash of configuration options:
:context - If your string represents a birthday, you can set this value to :past and if an ambiguous string is given, it will assume it is in the past. :now - Time, all computations will be based off of time instead of Time.now. :guess - By default the parser will guess a single point in time for the given date or time. If you'd rather have the entire time span returned, set this to false and a Chronic::Span will be returned. :ambiguous_time_range - If an Integer is given, ambiguous times (like 5:00) will be assumed to be within the range of that time in the AM to that time in the PM. For example, if you set it to `7`, then the parser will look for the time between 7am and 7pm. In the case of 5:00, it would assume that means 5:00pm. If `:none` is given, no assumption will be made, and the first matching instance of that time will be used. :endian_precedence - By default, Chronic will parse "03/04/2011" as the fourth day of the third month. Alternatively you can tell Chronic to parse this as the third day of the fourth month by setting this to [:little, :middle]. :ambiguous_year_future_bias - When parsing two digit years (ie 79) unlike Rubys Time class, Chronic will attempt to assume the full year using this figure. Chronic will look x amount of years into the future and past. If the two digit year is `now + x years` it's assumed to be the future, `now - x years` is assumed to be the past.
List of Handler definitions. See Chronic.parse for a list of options this method accepts.
options - An optional Hash of configuration options.
Returns a Hash of Handler definitions.
Guess a specific time within the given span.
span - The Chronic::Span object to calcuate a guess from.
Returns a new Time object.
Parse "text" with the given options Returns either a Time or Chronic::Span, depending on the value of options[:guess]
Clean up the specified text ready for parsing.
Clean up the string by stripping unwanted characters, converting idioms to their canonical form, converting number words to numbers (three => 3), and converting ordinal words to numeric ordinals (third => 3rd)
text - The String text to normalize.
Examples:
Chronic.pre_normalize('first day in May') #=> "1st day in may" Chronic.pre_normalize('tomorrow after noon') #=> "next day future 12:00" Chronic.pre_normalize('one hundred and thirty six days from now') #=> "136 days future this second"