Class: Pdfh::DateInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfh/utils/date_info.rb

Overview

Encapsulates date interpretation from regex captures. Responsible for converting raw captured strings into typed date values and deriving period groupings (quarter, bimester, period string).

Instance Method Summary collapse

Constructor Details

#initialize(date_captures) ⇒ self

Parameters:

  • date_captures (Hash{String => String})

    Captured date components. Keys: "m" (month — name or number), "y" (year — 2 or 4 digits), "d" (day, optional)



11
12
13
# File 'lib/pdfh/utils/date_info.rb', line 11

def initialize(date_captures)
  @date_captures = date_captures
end

Instance Method Details

#bimesterInteger

B1: Jan–Feb, B2: Mar–Apr, B3: May–Jun, B4: Jul–Aug, B5: Sep–Oct, B6: Nov–Dec

Returns:

  • (Integer)

    Bimester (1–6) based on the month



46
47
48
# File 'lib/pdfh/utils/date_info.rb', line 46

def bimester
  @bimester ||= ((month - 1) / 2) + 1
end

#capturesHash{String => String}

Returns Raw date captures as provided by the regex match.

Returns:

  • (Hash{String => String})

    Raw date captures as provided by the regex match



16
17
18
# File 'lib/pdfh/utils/date_info.rb', line 16

def captures
  @date_captures
end

#dayString?

Returns Day of month if captured, nil otherwise.

Returns:

  • (String, nil)

    Day of month if captured, nil otherwise



34
35
36
# File 'lib/pdfh/utils/date_info.rb', line 34

def day
  @date_captures["d"]
end

#monthInteger

Returns Normalized month number (1–12).

Returns:

  • (Integer)

    Normalized month number (1–12)



21
22
23
# File 'lib/pdfh/utils/date_info.rb', line 21

def month
  @month ||= Month.normalize_to_i(@date_captures["m"])
end

#periodString

Returns Period in format "YYYY-MM".

Returns:

  • (String)

    Period in format "YYYY-MM"



51
52
53
# File 'lib/pdfh/utils/date_info.rb', line 51

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

#quarterInteger

Q1: Jan–Mar, Q2: Apr–Jun, Q3: Jul–Sep, Q4: Oct–Dec

Returns:

  • (Integer)

    Quarter (1–4) based on the month



40
41
42
# File 'lib/pdfh/utils/date_info.rb', line 40

def quarter
  @quarter ||= ((month - 1) / 3) + 1
end

#yearInteger

Returns Full four-digit year (e.g., 2024).

Returns:

  • (Integer)

    Full four-digit year (e.g., 2024)



26
27
28
29
30
31
# File 'lib/pdfh/utils/date_info.rb', line 26

def year
  @year ||= begin
    raw = @date_captures["y"]
    (raw.size == 2 ? "20#{raw}" : raw).to_i
  end
end