Class: Pdfh::DocumentPeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfh/models/document_period.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month:, month_offset:, year:, day: nil) ⇒ self



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pdfh/models/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

Instance Attribute Details

#monthObject (readonly)

Returns the value of attribute month.



6
7
8
# File 'lib/pdfh/models/document_period.rb', line 6

def month
  @month
end

#yearObject (readonly)

Returns the value of attribute year.



6
7
8
# File 'lib/pdfh/models/document_period.rb', line 6

def year
  @year
end

Instance Method Details

#inspectString (frozen)

Returns:



33
34
35
# File 'lib/pdfh/models/document_period.rb', line 33

def inspect
  "<#{self.class} year=#{year} month=#{month}>"
end

#to_sString (frozen)

Returns:



28
29
30
# File 'lib/pdfh/models/document_period.rb', line 28

def to_s
  "#{year}-#{month.to_s.rjust(2, "0")}"
end