class ToParsedObj::Parsers
Public Instance Methods
add(ops,&b)
click to toggle source
# File lib/to_parsed_obj.rb, line 57 def add(ops,&b) ops[:convertor] ||= b if block_given? self.parsers << ToParsedObj::SingleParser.new(ops) end
add_basic!()
click to toggle source
# File lib/to_parsed_obj.rb, line 61 def add_basic! require 'date' add(:matcher => /^-?[0-9]+$/, :convertor => :to_i) add(:matcher => [/^-?[0-9\.]+$/,/^[^\.]*\.[^\.]*$/], :convertor => :to_f) add(:matcher => /^\d+[\/\\]\d+[\/\\]\d+$/) { |str| Date.parse(str) } add(:matcher => /^(\d+[\/\\]\d+[\/\\]\d+\s+\d+(?::\d+){1,99})/) do |str,single| m = single.match_obj[1].scan(/\d+/).map { |x| x.to_i } arr = [2,0,1].map { |i| m[i] } arr += m[3..-1].map { |x| x } Time.local(*arr) end add(:matcher => /^(\d+-\d+-\d+\s+\d+(?::\d+){1,99})\s+\-\d+$/) do |str,single| m = single.match_obj[1].scan(/\d+/).map { |x| x.to_i } Time.local(*m) end end
each_parser(one_time) { |parser| ... }
click to toggle source
# File lib/to_parsed_obj.rb, line 44 def each_parser(one_time,&b) one_time.each do |m,c| parser = ToParsedObj::SingleParser.new(:matcher => m, :convertor => c) yield(parser) end parsers.each(&b) end
parse(obj,one_time={})
click to toggle source
# File lib/to_parsed_obj.rb, line 51 def parse(obj,one_time={}) each_parser(one_time) do |parser| return parser.parse(obj) if parser.match?(obj) end obj end