Class: Bibox::Models::Base
- Inherits:
-
Object
- Object
- Bibox::Models::Base
- Defined in:
- lib/bibox/models/base.rb
Direct Known Subclasses
Asset, Bill, Contract, OHLCV, Order, Pair, Ticker, Trade, Transfer, UserAssets
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(hash) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(hash) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bibox/models/base.rb', line 5 def initialize(hash) self.class::MAPPING.keys.each { |key| self.class.send(:attr_accessor, key) } hash.each do |key, value| key = key.underscore.to_sym type = self.class::MAPPING.fetch(key, nil) value = value && type ? ::Bibox::Utilities::convert_value(value, type, use_ms_for_time: true) : value self.send("#{key}=", value) if self.respond_to?(key) end end |
Class Method Details
.parse(data) ⇒ Object
20 21 22 |
# File 'lib/bibox/models/base.rb', line 20 def self.parse(data) data&.collect { |item| self.new(item) } end |
Instance Method Details
#attributes ⇒ Object
16 17 18 |
# File 'lib/bibox/models/base.rb', line 16 def attributes Hash[instance_variables.map { |name| [name.to_s.gsub(/^@/, "").to_sym, instance_variable_get(name)] }] end |