Class: Quant::SecurityClass
- Inherits:
-
Object
- Object
- Quant::SecurityClass
- Defined in:
- lib/quant/security_class.rb
Overview
Foreign Exchange (Forex): The market where currencies are traded. Investors can buy and sell currencies to profit from changes in exchange rates.
Constant Summary collapse
- CLASSES =
%i( bond commodity cryptocurrency etf forex future mbs mutual_fund option preferred_stock reit stock treasury_note ).freeze
Instance Attribute Summary collapse
-
#security_class ⇒ Object
readonly
Returns the value of attribute security_class.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name) ⇒ SecurityClass
constructor
A new instance of SecurityClass.
- #raise_unknown_security_class_error(name) ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ SecurityClass
Returns a new instance of SecurityClass.
62 63 64 65 66 67 |
# File 'lib/quant/security_class.rb', line 62 def initialize(name) return if @security_class = from_standard(name) @security_class = from_alternate(name.to_s.downcase.to_sym) unless name.nil? raise_unknown_security_class_error(name) unless security_class end |
Instance Attribute Details
#security_class ⇒ Object (readonly)
Returns the value of attribute security_class.
60 61 62 |
# File 'lib/quant/security_class.rb', line 60 def security_class @security_class end |
Instance Method Details
#==(other) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/quant/security_class.rb', line 91 def ==(other) case other when String then from_alternate(other.to_sym) == security_class when Symbol then from_alternate(other) == security_class when SecurityClass then other.security_class == security_class else false end end |
#raise_unknown_security_class_error(name) ⇒ Object
75 76 77 |
# File 'lib/quant/security_class.rb', line 75 def raise_unknown_security_class_error(name) raise SecurityClassError, "Unknown security class: #{name.inspect}" end |
#to_h ⇒ Object
83 84 85 |
# File 'lib/quant/security_class.rb', line 83 def to_h { "sc" => security_class } end |
#to_json(*args) ⇒ Object
87 88 89 |
# File 'lib/quant/security_class.rb', line 87 def to_json(*args) Oj.dump(to_h, *args) end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/quant/security_class.rb', line 79 def to_s security_class.to_s end |