Class: SecApi::Period
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- SecApi::Period
- Defined in:
- lib/sec_api/objects/period.rb
Overview
Immutable value object representing a time period for XBRL facts.
Periods can be either:
-
Duration: has start_date and end_date (for income statement items)
-
Instant: has instant date (for balance sheet items)
Class Method Summary collapse
-
.from_api(data) ⇒ Period
Parses API response data into a Period object.
Instance Method Summary collapse
-
#duration? ⇒ Boolean
Returns true if this is a duration period (has start/end dates).
-
#initialize(attributes) ⇒ Period
constructor
A new instance of Period.
-
#instant? ⇒ Boolean
Returns true if this is an instant period (point-in-time).
Constructor Details
#initialize(attributes) ⇒ Period
Returns a new instance of Period.
44 45 46 47 |
# File 'lib/sec_api/objects/period.rb', line 44 def initialize(attributes) super freeze end |
Class Method Details
.from_api(data) ⇒ Period
Parses API response data into a Period object.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sec_api/objects/period.rb', line 58 def self.from_api(data) # Defensive nil check for direct calls (Fact.from_api validates period presence) return nil if data.nil? start_date = data[:startDate] || data["startDate"] || data[:start_date] || data["start_date"] end_date = data[:endDate] || data["endDate"] || data[:end_date] || data["end_date"] instant = data[:instant] || data["instant"] validate_structure!(instant, start_date, end_date, data) new( start_date: start_date, end_date: end_date, instant: instant ) end |
Instance Method Details
#duration? ⇒ Boolean
Returns true if this is a duration period (has start/end dates)
33 34 35 |
# File 'lib/sec_api/objects/period.rb', line 33 def duration? !start_date.nil? && !end_date.nil? end |
#instant? ⇒ Boolean
Returns true if this is an instant period (point-in-time)
40 41 42 |
# File 'lib/sec_api/objects/period.rb', line 40 def instant? !instant.nil? end |