Class: Kucoin::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kucoin/models/base.rb

Direct Known Subclasses

Balance, Coin, CoinAddress, Deal, OHLCV, Ticker, Trade, User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
14
# File 'lib/kucoin/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.to_s.underscore.to_sym
    type            =     self.class::MAPPING.fetch(key, nil)
    value           =     value && type ? ::Kucoin::Utilities::Parsing.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/kucoin/models/base.rb', line 20

def self.parse(data)
  data&.collect { |item| self.new(item) }
end

Instance Method Details

#attributesObject



16
17
18
# File 'lib/kucoin/models/base.rb', line 16

def attributes
  Hash[instance_variables.map { |name| [name.to_s.gsub(/^@/, "").to_sym, instance_variable_get(name)] }]
end