class Mhc::Query::RelationalExpression
Constants
- KEYWORDS
Public Class Methods
new(context)
click to toggle source
# File lib/mhc/query.rb, line 76 def initialize(context) @name = context.expect(:symbol).value.downcase.to_sym raise ParseError, "unknown keyword '#{@name}'" unless KEYWORDS.member?(@name) context.expect(:sepop) # Currently, operator is only ":" @arguments = [] if context.eat_if(:lbracket) loop do @arguments << Argument.new(context) break if context.eat_if(:rbracket) end else @arguments << Argument.new(context) end end
Public Instance Methods
to_proc()
click to toggle source
# File lib/mhc/query.rb, line 93 def to_proc case @name when :category @arguments = @arguments.map{|arg| arg.value.downcase} return lambda {|ev| !(ev.categories.map{|c| c.to_s.downcase} & @arguments).empty?} when :recurrence_tag @arguments = @arguments.map{|arg| arg.value.downcase} return lambda {|ev| !!@arguments.find{|v| ev.send(@name).to_s.downcase.toutf8 == v}} else @arguments = @arguments.map{|arg| Regexp.quote(arg.value)} return lambda {|ev| !!@arguments.find{|v| ev.send(@name).to_s.toutf8.match(v)}} end end