Class: String

Public Instance Methods


to_date_lex ()

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

to_date_time_lex ()

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

to_i_lex ()

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

to_time_lex ()

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