Object
Convert a string to a Date. This method will only work on strings that match the format %Y%m%d %H%M%S, otherwise the result will be unpredictable.
# File lib/ferret/number_tools.rb, line 134 def to_date_lex return Date.strptime(self + "-02-01", "%Y-%m-%d") end
Convert a string to a DateTime. This method will only work on strings that match the format %Y%m%d %H%M%S, otherwise the result will be unpredictable.
# File lib/ferret/number_tools.rb, line 140 def to_date_time_lex return DateTime.strptime(self + "-01-01", "%Y-%m-%d %H:%M:%S") end
Convert a string to an integer. This method will only work on strings that were previously created with Integer#to_s_lex, otherwise the result will be unpredictable.
# File lib/ferret/number_tools.rb, line 115 def to_i_lex if (self[0] == --) return self[(Integer::LEN_STR_SIZE + 1)..-1].to_i - 10 ** (self.size - Integer::LEN_STR_SIZE - 1) else return self[Integer::LEN_STR_SIZE..-1].to_i end end
Convert a string to a Time. This method will only work on strings that match the format %Y%m%d %H%M%S, otherwise the result will be unpredictable.
# File lib/ferret/number_tools.rb, line 126 def to_time_lex vals = [] self.gsub(/(?:^|[- :])(\d+)/) {vals << $1.to_i; $&} Time.mktime(*vals) end
Generated with the Darkfish Rdoc Generator 2.