Class: SecApi::ExtractedData
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- SecApi::ExtractedData
- Includes:
- DeepFreezable
- Defined in:
- lib/sec_api/objects/extracted_data.rb
Overview
Represents extracted data from SEC filings
This immutable value object wraps extraction results from the sec-api.io Extractor endpoint. All attributes are optional to handle varying API response structures across different form types.
Class Method Summary collapse
-
.from_api(data) ⇒ ExtractedData
Normalize API response (handle string vs symbol keys).
Instance Method Summary collapse
-
#initialize(attributes) ⇒ ExtractedData
constructor
Explicit freeze for immutability and thread safety Deep freeze all nested hashes and strings to ensure thread safety.
-
#metadata ⇒ Hash?
Metadata about extraction Flexible hash to handle varying API response structures.
-
#method_missing(name, *args) ⇒ String?
Access a specific section by name using dynamic method dispatch.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Support respond_to? for sections that exist in the hash.
-
#sections ⇒ Hash{Symbol => String}?
Structured sections (risk_factors, financials, etc.) API returns hash like { “risk_factors”: “…”, “financials”: “…” }.
-
#text ⇒ String?
Full extracted text (if extracting entire filing).
Constructor Details
#initialize(attributes) ⇒ ExtractedData
Explicit freeze for immutability and thread safety Deep freeze all nested hashes and strings to ensure thread safety
50 51 52 53 54 55 56 |
# File 'lib/sec_api/objects/extracted_data.rb', line 50 def initialize(attributes) super text&.freeze deep_freeze(sections) if sections deep_freeze() if freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ String?
Access a specific section by name using dynamic method dispatch
Allows convenient access to sections via method calls instead of hash access. Returns nil for missing sections (no NoMethodError raised for section names). Methods with special suffixes (!, ?, =) still raise NoMethodError.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sec_api/objects/extracted_data.rb', line 85 def method_missing(name, *args) # Only handle zero-argument calls (getter-style) return super if args.any? # Don't intercept bang, predicate, or setter methods name_str = name.to_s return super if name_str.end_with?("!", "?", "=") # Return section content if sections exist, nil otherwise sections&.[](name) end |
Class Method Details
.from_api(data) ⇒ ExtractedData
Normalize API response (handle string vs symbol keys)
62 63 64 65 66 67 68 |
# File 'lib/sec_api/objects/extracted_data.rb', line 62 def self.from_api(data) new( text: data["text"] || data[:text], sections: normalize_sections(data["sections"] || data[:sections]), metadata: data["metadata"] || data[:metadata] || {} ) end |
Instance Method Details
#metadata ⇒ Hash?
Metadata about extraction Flexible hash to handle varying API response structures
45 |
# File 'lib/sec_api/objects/extracted_data.rb', line 45 attribute? :metadata, Types::Hash.optional |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Support respond_to? for sections that exist in the hash
Only responds true for section names that are actually present in the sections hash. This allows proper Ruby introspection.
105 106 107 |
# File 'lib/sec_api/objects/extracted_data.rb', line 105 def respond_to_missing?(name, include_private = false) sections&.key?(name) || super end |
#sections ⇒ Hash{Symbol => String}?
Structured sections (risk_factors, financials, etc.) API returns hash like { “risk_factors”: “…”, “financials”: “…” }
40 |
# File 'lib/sec_api/objects/extracted_data.rb', line 40 attribute? :sections, Types::Hash.map(Types::Symbol, Types::String).optional |
#text ⇒ String?
Full extracted text (if extracting entire filing)
35 |
# File 'lib/sec_api/objects/extracted_data.rb', line 35 attribute? :text, Types::String.optional |