class Rbtce::PairBuilder
Constants
- VALID_PAIRS
Public Class Methods
new( options )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 24 def initialize( options ) @end_point = options.fetch( :end_point ) @target_class = options.fetch( :class ) @pairs = [] reset_current_pair end
Public Instance Methods
and( options={} )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 41 def and( options={} ) return self if @pairs.include?( @current_pair ) validate_pair!( @current_pair ) if options.fetch( :validate, true ) @pairs << @current_pair reset_current_pair self end
Also aliased as: flash_pair
fetch( options={} )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 50 def fetch( options={} ) flash_pair @target_class.build( @pairs, Client.get( "#{@end_point}/#{pairs_path}", options ) ) end
from( currency )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 31 def from( currency ) @current_pair[:from] = currency self end
to( currency )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 36 def to( currency ) @current_pair[:to] = currency self end
Private Instance Methods
pairs_path()
click to toggle source
# File lib/rbtce/pair_builder.rb, line 65 def pairs_path @pairs.map { |pair| "#{pair[:from]}_#{pair[:to]}" }.join( '-' ) end
reset_current_pair()
click to toggle source
# File lib/rbtce/pair_builder.rb, line 57 def reset_current_pair @current_pair = { from: nil, to: nil } end
validate_pair!( pair )
click to toggle source
# File lib/rbtce/pair_builder.rb, line 61 def validate_pair!( pair ) raise "Invalid pair: '#{pair.inspect}'" unless VALID_PAIRS.include?( pair ) end