class Rbtce::BaseModel

Attributes

symbol[R]

Public Class Methods

build( pairs, response ) click to toggle source
# File lib/rbtce/base_model.rb, line 25
def self.build( pairs, response )
  elements = pairs.map { |pair|
    symbol = "#{pair[:from]}_#{pair[:to]}"
    symbol_element = response.fetch( symbol )
    if symbol_element.is_a?( Hash )
      new( symbol, symbol_element )
    else
      symbol_element.map { |options| new( symbol, options ) }
    end
  }
  elements.length < 2 ? elements.first : elements
end
from( currency ) click to toggle source
# File lib/rbtce/base_model.rb, line 15
def self.from( currency )
  PairBuilder.new( end_point: end_point, class: self ).from( currency )
end
new( symbol, options ) click to toggle source
# File lib/rbtce/base_model.rb, line 5
def initialize( symbol, options )
  @symbol = symbol
  @_options = options
  required_fields.each do |field_name|
    val = options.fetch( field_name )
    val = Time.at( val ) if date_fields.include?( field_name )
    instance_variable_set( "@#{field_name}", val )
  end
end

Private Class Methods

end_point() click to toggle source
# File lib/rbtce/base_model.rb, line 40
def self.end_point
  raise MethodNotImplemented
end

Public Instance Methods

to_json( options={} ) click to toggle source
# File lib/rbtce/base_model.rb, line 19
def to_json( options={} )
  include_root = options.fetch( :include_root, false )
  include_root ? Hash[symbol, @_options].to_json : @_options.to_json
end
Also aliased as: to_s
to_s( options={} )
Alias for: to_json

Private Instance Methods

date_fields() click to toggle source
# File lib/rbtce/base_model.rb, line 48
def date_fields; []; end
required_fields() click to toggle source
# File lib/rbtce/base_model.rb, line 44
def required_fields
  raise MethodNotImplemented
end