Class: SecApi::Objects::Entity

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/sec_api/objects/entity.rb

Overview

Represents a company or issuer entity from SEC EDGAR.

Entity objects are returned from mapping API calls and contain identifying information such as CIK, ticker, company name, and regulatory details. All instances are immutable (frozen).

Examples:

Entity from ticker resolution

entity = client.mapping.ticker("AAPL")
entity.cik      # => "0000320193"
entity.ticker   # => "AAPL"
entity.name     # => "Apple Inc."

Entity from CIK resolution

entity = client.mapping.cik("320193")
entity.ticker   # => "AAPL"

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Entity

Override constructor to ensure immutability



52
53
54
55
# File 'lib/sec_api/objects/entity.rb', line 52

def initialize(attributes)
  super
  freeze
end

Class Method Details

.from_api(data) ⇒ Entity

Creates an Entity from API response data.

Normalizes camelCase keys from the API to snake_case and handles both symbol and string keys in the input hash.

Examples:

data = { cik: "0000320193", companyName: "Apple Inc.", ticker: "AAPL" }
entity = Entity.from_api(data)
entity.name  # => "Apple Inc."

Parameters:

  • data (Hash)

    API response hash with entity data

Returns:

  • (Entity)

    Immutable entity object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sec_api/objects/entity.rb', line 70

def self.from_api(data)
  # Non-destructive normalization - create new hash instead of mutating input
  normalized = {
    cik: data[:cik] || data["cik"],
    name: data[:name] || data[:companyName] || data["name"] || data["companyName"],
    irs_number: data[:irs_number] || data[:irsNo] || data["irs_number"] || data["irsNo"],
    state_of_incorporation: data[:state_of_incorporation] || data[:stateOfIncorporation] || data["state_of_incorporation"] || data["stateOfIncorporation"],
    fiscal_year_end: data[:fiscal_year_end] || data[:fiscalYearEnd] || data["fiscal_year_end"] || data["fiscalYearEnd"],
    type: data[:type] || data["type"],
    act: data[:act] || data["act"],
    file_number: data[:file_number] || data[:fileNo] || data["file_number"] || data["fileNo"],
    film_number: data[:film_number] || data[:filmNo] || data["film_number"] || data["filmNo"],
    sic: data[:sic] || data["sic"],
    ticker: data[:ticker] || data["ticker"],
    exchange: data[:exchange] || data["exchange"],
    cusip: data[:cusip] || data["cusip"]
  }

  new(normalized)
end