module AMarmita::Helpers
Constants
- MONTH_NAMES_PT
Public Instance Methods
blank?(object)
click to toggle source
# File lib/a_marmita/helpers.rb, line 60 def blank?(object) case object when String object == '' else object.nil? end end
cart_date_parser(string)
click to toggle source
# File lib/a_marmita/helpers.rb, line 32 def cart_date_parser(string) return nil if string.nil? day, month = *string.scan(/.* - ([0-9]*) (.*)/).flatten format_date "#{Date.today.year}-#{get_month_number(month)}-#{day}" end
date_parser(date)
click to toggle source
# File lib/a_marmita/helpers.rb, line 40 def date_parser(date) if date.is_a?(String) date = Date.parse(date) rescue nil end date end
format_date(date)
click to toggle source
# File lib/a_marmita/helpers.rb, line 48 def format_date(date) date = date_parser(date) date = (Date.today + 1) unless date.respond_to?(:strftime) date.strftime('%Y-%m-%d') end
get_month_number(month)
click to toggle source
# File lib/a_marmita/helpers.rb, line 56 def get_month_number(month) MONTH_NAMES_PT.index(month.downcase) end
to_float(string)
click to toggle source
# File lib/a_marmita/helpers.rb, line 24 def to_float(string) return 0 if string.nil? values = string.scan(/\d+[,.]*\d*/).flatten.map(&:to_f) values.length > 1 ? values : values.first end
to_int(string)
click to toggle source
# File lib/a_marmita/helpers.rb, line 20 def to_int(string) string.nil? ? 0 : string.gsub(/[^0-9]/, '').to_i end
try(object, *a) { |object| ... }
click to toggle source
# File lib/a_marmita/helpers.rb, line 12 def try(object, *a, &b) if a.empty? && block_given? yield object else object.respond_to?(a.first) ? object.public_send(*a, &b) : nil end end