module StockHistory::Utility
> StockHistory
Utility
Methods¶ ↑
Public Instance Methods
min_date(first, second)
click to toggle source
# File lib/stock_history/utility.rb, line 7 def min_date(first, second) first < second ? first : second end
to_date(string)
click to toggle source
# File lib/stock_history/utility.rb, line 38 def to_date(string) if string.is_a?(String) && string.match(/\d{4}-\d{2}-\d{2}/) Date.strptime(string, '%Y-%m-%d') elsif string.is_a?(String) && string.match(/\d{2}\/\d{2}\/\d{4}/) Date.strptime(string, '%m/%d/%Y') elsif string.is_a?(String) && string.match(/\d{8}/) Date.strptime(string, '%Y%m%d') else string end end
to_format(string)
click to toggle source
# File lib/stock_history/utility.rb, line 11 def to_format(string) to_fs(to_date(string)) end
to_fs(string)
click to toggle source
# File lib/stock_history/utility.rb, line 24 def to_fs(string) (!!Float(string) rescue false) ? Float(string) : string end
to_p(string)
click to toggle source
# File lib/stock_history/utility.rb, line 28 def to_p(string) if string.is_a?(String) to_p(string.split(',')) elsif string.is_a?(Array) "'#{string.join("','").gsub(" ", "").upcase}'" else string end end
to_underscore(string)
click to toggle source
# File lib/stock_history/utility.rb, line 15 def to_underscore(string) string = string.gsub(/::/, '/') string.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') string.gsub!(/([a-z\d])([A-Z])/, '\1_\2') string.tr!('-', '_') string.downcase! string end