class Pdfh::DocumentPeriod

Calculate correct period from the extracted document date and subtype month offset

Attributes

month[R]
year[R]

Public Class Methods

new(month:, month_offset:, year:, day: nil) click to toggle source

@return [self]

# File lib/pdfh/document_period.rb, line 9
def initialize(month:, month_offset:, year:, day: nil)
  @day = day
  @raw_month = month
  @raw_year = year
  normalized_month = Month.normalize_to_i(month) + (month_offset || 0)
  year_offset = 0
  @month = case normalized_month
           when 0
             year_offset = -1
             12
           when 13
             year_offset = 1
             1
           else normalized_month
           end
  @year = (year.size == 2 ? "20#{year}" : year).to_i + year_offset
end

Public Instance Methods

to_s() click to toggle source

@return [String]

# File lib/pdfh/document_period.rb, line 28
def to_s
  "#{year}-#{month.to_s.rjust(2, "0")}"
end