class Temporal::Parser
Public Class Methods
add_literal(literal, &block)
click to toggle source
# File lib/temporal/parser.rb, line 5 def self.add_literal literal, &block @@literals[ literal ] = block end
match?(string)
click to toggle source
# File lib/temporal/parser.rb, line 9 def self.match? string to_match = string.downcase.strip @@literals.keys.each do |key| return true if to_match =~ key end return false end
parse(string)
click to toggle source
# File lib/temporal/parser.rb, line 17 def self.parse string @@literals.keys.each do |key| match = string.match(key) next unless match result = [] result << parse(match.pre_match) if match.pre_match.strip.size > 0 result << @@literals[key].call result << parse(match.post_match) if match.post_match.strip.size > 0 result.flatten! if result.empty? result = nil else result = result.pop if result.size == 1 end return result end string end