Module: IceCube::English::RuleExtension::ClassMethods

Defined in:
lib/ice_cube/english/rule_extension.rb

Instance Method Summary collapse

Instance Method Details

#from_english(string, options = {}) ⇒ Object

Return a new IceCube rule corresponding to the specified english string.

If the :multiple option is set, return an Array of rules.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ice_cube/english/rule_extension.rb', line 16

def from_english(string, options={})
  if options[:multiple]
    grammar = ::IceCube::English::ScheduleGrammarParser.new
    parse_tree = grammar.parse(string.downcase)
    raise ArgumentError.new(grammar.failure_reason) unless parse_tree
    parse_tree.attribute_hashes.map{ |h| from_hash(h) }
  else
    grammar = ::IceCube::English::RuleGrammarParser.new
    parse_tree = grammar.parse(string.downcase)
    raise ArgumentError.new(grammar.failure_reason) unless parse_tree
    from_hash(parse_tree.attributes)
  end
end