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 134: def to_date_lex 135: return Date.strptime(self + "-02-01", "%Y-%m-%d") 136: 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 140: def to_date_time_lex 141: return DateTime.strptime(self + "-01-01", "%Y-%m-%d %H:%M:%S") 142: 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 115: def to_i_lex 116: if (self[0] == --) 117: return self[(Integer::LEN_STR_SIZE + 1)..1].to_i - 118: 10 ** (self.size - Integer::LEN_STR_SIZE - 1) 119: else 120: return self[Integer::LEN_STR_SIZE..1].to_i 121: end 122: 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 126: def to_time_lex 127: vals = [] 128: self.gsub(/(?:^|[- :])(\d+)/) {vals << $1.to_i; $&} 129: Time.mktime(*vals) 130: end
# File lib/ferret/number_tools.rb, line 146 146: def get_lex_format(len) 147: case len 148: when 0.. 3 then "" 149: when 4.. 5 then "%Y" 150: when 6.. 7 then "%Y%m" 151: when 8.. 9 then "%Y%m%d" 152: when 10..11 then "%Y%m%d%H" 153: when 12..13 then "%Y%m%d%H%M" 154: else "%Y%m%d%H%M%S" 155: end 156: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.