Class: SchwabRb::DataObjects::OptionDeliverable

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/instrument.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_symbol:, symbol:, deliverable_units:, deliverable_number:, strike_percent:, deliverable:) ⇒ OptionDeliverable

Returns a new instance of OptionDeliverable.



75
76
77
78
79
80
81
82
# File 'lib/schwab_rb/data_objects/instrument.rb', line 75

def initialize(root_symbol:, symbol:, deliverable_units:, deliverable_number:, strike_percent:, deliverable:)
  @root_symbol = root_symbol
  @symbol = symbol
  @deliverable_units = deliverable_units
  @deliverable_number = deliverable_number
  @strike_percent = strike_percent
  @deliverable = deliverable
end

Instance Attribute Details

#deliverableObject (readonly)

Returns the value of attribute deliverable.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def deliverable
  @deliverable
end

#deliverable_numberObject (readonly)

Returns the value of attribute deliverable_number.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def deliverable_number
  @deliverable_number
end

#deliverable_unitsObject (readonly)

Returns the value of attribute deliverable_units.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def deliverable_units
  @deliverable_units
end

#root_symbolObject (readonly)

Returns the value of attribute root_symbol.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def root_symbol
  @root_symbol
end

#strike_percentObject (readonly)

Returns the value of attribute strike_percent.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def strike_percent
  @strike_percent
end

#symbolObject (readonly)

Returns the value of attribute symbol.



62
63
64
# File 'lib/schwab_rb/data_objects/instrument.rb', line 62

def symbol
  @symbol
end

Class Method Details

.build(data) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/schwab_rb/data_objects/instrument.rb', line 64

def self.build(data)
  new(
    root_symbol: data.fetch(:rootSymbol, nil),
    symbol: data.fetch(:symbol, nil),
    strike_percent: data.fetch(:strikePercent, nil),
    deliverable_number: data.fetch(:deliverableNumber, nil),
    deliverable_units: data.fetch(:deliverableUnits),
    deliverable: data.fetch(:deliverable, nil).then { |d| d.nil? ? nil : Instrument.build(d) }
  )
end

Instance Method Details

#to_hObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/schwab_rb/data_objects/instrument.rb', line 84

def to_h
  {
    rootSymbol: @root_symbol,
    symbol: @symbol,
    strikePercent: @strike_percent,
    deliverableNumber: @deliverable_number,
    deliverableUnits: @deliverable_units,
    deliverable: @deliverable&.to_h
  }.compact
end