Class: SQA::DataFrame::Data
- Inherits:
-
Object
- Object
- SQA::DataFrame::Data
- Defined in:
- lib/sqa/data_frame/data.rb
Overview
Data class to store stock metadata
This class holds metadata about a stock including its ticker symbol, name, exchange, data source, technical indicators, and company overview.
Instance Attribute Summary collapse
-
#exchange ⇒ String?
Exchange where stock trades (e.g., ‘NASDAQ’, ‘NYSE’).
-
#indicators ⇒ Hash
Technical indicators configuration and cached values.
-
#name ⇒ String?
Company name.
-
#overview ⇒ Hash
Company overview data from API.
-
#source ⇒ Symbol
Data source (:alpha_vantage, :yahoo_finance).
-
#ticker ⇒ String?
Stock ticker symbol (e.g., ‘AAPL’, ‘MSFT’).
Instance Method Summary collapse
-
#initialize(data_hash = nil, ticker: nil, name: nil, exchange: nil, source: :alpha_vantage, indicators: {}, overview: {}) ⇒ Data
constructor
Initializes stock metadata.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_json(*args) ⇒ String
Serialize to JSON string.
-
#to_s ⇒ String
(also: #inspect)
String representation.
Constructor Details
#initialize(data_hash = nil, ticker: nil, name: nil, exchange: nil, source: :alpha_vantage, indicators: {}, overview: {}) ⇒ Data
Initializes stock metadata.
Can be called in two ways:
1. With a hash: SQA::DataFrame::Data.new(hash) - for JSON deserialization
2. With keyword args: SQA::DataFrame::Data.new(ticker: 'AAPL', source: :alpha_vantage, ...)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sqa/data_frame/data.rb', line 52 def initialize(data_hash = nil, ticker: nil, name: nil, exchange: nil, source: :alpha_vantage, indicators: {}, overview: {}) if data_hash.is_a?(Hash) && ticker.nil? # Initialize from hash (JSON deserialization) - called as: new(hash) @ticker = data_hash['ticker'] || data_hash[:ticker] @name = data_hash['name'] || data_hash[:name] @exchange = data_hash['exchange'] || data_hash[:exchange] @source = data_hash['source'] || data_hash[:source] || source @indicators = data_hash['indicators'] || data_hash[:indicators] || {} @overview = data_hash['overview'] || data_hash[:overview] || {} # Convert source to symbol if it's a string @source = @source.to_sym if @source.is_a?(String) else # Initialize from named parameters - called as: new(ticker: 'AAPL', ...) @ticker = ticker @name = name @exchange = exchange @source = source @indicators = indicators @overview = overview end end |
Instance Attribute Details
#exchange ⇒ String?
36 |
# File 'lib/sqa/data_frame/data.rb', line 36 attr_accessor :ticker, :name, :exchange, :source, :indicators, :overview |
#indicators ⇒ Hash
36 |
# File 'lib/sqa/data_frame/data.rb', line 36 attr_accessor :ticker, :name, :exchange, :source, :indicators, :overview |
#name ⇒ String?
36 |
# File 'lib/sqa/data_frame/data.rb', line 36 attr_accessor :ticker, :name, :exchange, :source, :indicators, :overview |
#overview ⇒ Hash
36 |
# File 'lib/sqa/data_frame/data.rb', line 36 attr_accessor :ticker, :name, :exchange, :source, :indicators, :overview |
#source ⇒ Symbol
36 |
# File 'lib/sqa/data_frame/data.rb', line 36 attr_accessor :ticker, :name, :exchange, :source, :indicators, :overview |
#ticker ⇒ String?
36 37 38 |
# File 'lib/sqa/data_frame/data.rb', line 36 def ticker @ticker end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sqa/data_frame/data.rb', line 85 def to_h { ticker: @ticker, name: @name, exchange: @exchange, source: @source, indicators: @indicators, overview: @overview } end |
#to_json(*args) ⇒ String
Serialize to JSON string
78 79 80 |
# File 'lib/sqa/data_frame/data.rb', line 78 def to_json(*args) to_h.to_json(*args) end |
#to_s ⇒ String Also known as: inspect
String representation
99 100 101 |
# File 'lib/sqa/data_frame/data.rb', line 99 def to_s "#{@ticker || 'Unknown'} (#{@exchange || 'N/A'}) via #{@source}" end |