class Pdfh::Month
Handles Month
conversions
Constants
- FINDER_3L
- FINDER_FL
- MONTHS_EN
rubocop:disable Layout/SpaceInsideArrayPercentLiteral
- MONTHS_ES
Public Class Methods
normalize_to_i(month)
click to toggle source
@param [String] month @return [Integer]
# File lib/pdfh/month.rb, line 17 def normalize_to_i(month) # When param is a number month_num = month.to_i raise ArgumentError, "Month #{month.inspect} is not a valid month number" if month_num > 12 return month_num if month_num.between?(1, 12) # When param is a 3 char month: 'mar', 'nov' return find_month(month, FINDER_3L) if month.size == 3 # When param has a direct match find_month(month, FINDER_FL) end
Private Class Methods
find_month(name, finder)
click to toggle source
@return [Integer]
# File lib/pdfh/month.rb, line 34 def find_month(name, finder) find_by_name = finder.curry[name] match = MONTHS_ES.find(&find_by_name) return month_number(MONTHS_ES, match) if match match = MONTHS_EN.find(&find_by_name) return month_number(MONTHS_EN, match) if match raise ArgumentError, "Month #{name.inspect} is not valid" end
month_number(month_array, name)
click to toggle source
@return [Integer]
# File lib/pdfh/month.rb, line 46 def month_number(month_array, name) month_array.rindex(name) + 1 end