Class: Pdfh::DateInfo
- Inherits:
-
Object
- Object
- Pdfh::DateInfo
- 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
-
#bimester ⇒ Integer
B1: Jan–Feb, B2: Mar–Apr, B3: May–Jun, B4: Jul–Aug, B5: Sep–Oct, B6: Nov–Dec.
-
#captures ⇒ Hash{String => String}
Raw date captures as provided by the regex match.
-
#day ⇒ String?
Day of month if captured, nil otherwise.
- #initialize(date_captures) ⇒ self constructor
-
#month ⇒ Integer
Normalized month number (1–12).
-
#period ⇒ String
Period in format "YYYY-MM".
-
#quarter ⇒ Integer
Q1: Jan–Mar, Q2: Apr–Jun, Q3: Jul–Sep, Q4: Oct–Dec.
-
#year ⇒ Integer
Full four-digit year (e.g., 2024).
Constructor Details
#initialize(date_captures) ⇒ self
11 12 13 |
# File 'lib/pdfh/utils/date_info.rb', line 11 def initialize(date_captures) @date_captures = date_captures end |
Instance Method Details
#bimester ⇒ Integer
B1: Jan–Feb, B2: Mar–Apr, B3: May–Jun, B4: Jul–Aug, B5: Sep–Oct, B6: Nov–Dec
46 47 48 |
# File 'lib/pdfh/utils/date_info.rb', line 46 def bimester @bimester ||= ((month - 1) / 2) + 1 end |
#captures ⇒ Hash{String => String}
Returns 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 |
#day ⇒ String?
Returns 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 |
#month ⇒ Integer
Returns 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 |
#period ⇒ String
Returns 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 |
#quarter ⇒ Integer
Q1: Jan–Mar, Q2: Apr–Jun, Q3: Jul–Sep, Q4: Oct–Dec
40 41 42 |
# File 'lib/pdfh/utils/date_info.rb', line 40 def quarter @quarter ||= ((month - 1) / 3) + 1 end |
#year ⇒ Integer
Returns 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 |