class ToParsedObj::SingleParser
Attributes
convertor[RW]
match_obj[RW]
matcher[RW]
Public Instance Methods
match?(obj,m=matcher)
click to toggle source
# File lib/to_parsed_obj.rb, line 9 def match?(obj,m=matcher) self.match_obj = if m.kind_of?(Regexp) m.match(obj.to_s.strip) elsif m.respond_to?(:call) m.call(obj) elsif m.kind_of?(Array) m.all? { |x| match?(obj,x) } elsif m.kind_of?(Class) obj.kind_of?(m) else m == obj end !!match_obj end
parse(obj)
click to toggle source
# File lib/to_parsed_obj.rb, line 23 def parse(obj) if convertor.kind_of?(Symbol) || convertor.kind_of?(String) obj.send(convertor) elsif convertor.kind_of?(Class) convertor.new(obj) elsif convertor.respond_to?(:call) if convertor.arity == 1 convertor.call(obj) elsif convertor.arity == 0 convertor.call else convertor.call(obj,self) end else "dunno how to convert" end end