Class: BBMB::Html::State::History::PositionFacade

Inherits:
Object
  • Object
show all
Defined in:
lib/bbmb/html/state/history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePositionFacade

Returns a new instance of PositionFacade.



14
15
16
17
18
19
# File 'lib/bbmb/html/state/history.rb', line 14

def initialize
  @positions = []
  @quantity = 0
  @prices = []
  @total = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object



35
36
37
# File 'lib/bbmb/html/state/history.rb', line 35

def method_missing(key, *args, &block)
  @positions.last.send(key, *args, &block)
end

Instance Attribute Details

#quantityObject (readonly)

Returns the value of attribute quantity.



13
14
15
# File 'lib/bbmb/html/state/history.rb', line 13

def quantity
  @quantity
end

#totalObject (readonly)

Returns the value of attribute total.



13
14
15
# File 'lib/bbmb/html/state/history.rb', line 13

def total
  @total
end

Instance Method Details

#add(position) ⇒ Object



20
21
22
23
24
25
# File 'lib/bbmb/html/state/history.rb', line 20

def add(position)
  @positions.push(position)
  @quantity += position.quantity
  @prices.push(position.price)
  @total = position.total + @total
end

#order_countObject



26
27
28
# File 'lib/bbmb/html/state/history.rb', line 26

def order_count
  @positions.size
end

#price_extremesObject



29
30
31
# File 'lib/bbmb/html/state/history.rb', line 29

def price_extremes
  [@prices.min, @prices.max]
end

#respond_to?(key) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bbmb/html/state/history.rb', line 32

def respond_to?(key)
  super || @positions.last.respond_to?(key)
end