Class: BBMB::Html::State::History::HistoryFacade

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHistoryFacade

Returns a new instance of HistoryFacade.



42
43
44
45
# File 'lib/bbmb/html/state/history.rb', line 42

def initialize
  @map = {}
  @positions = []
end

Instance Attribute Details

#sortedObject

Returns the value of attribute sorted.



41
42
43
# File 'lib/bbmb/html/state/history.rb', line 41

def sorted
  @sorted
end

Instance Method Details

#add(order) ⇒ Object



46
47
48
49
50
# File 'lib/bbmb/html/state/history.rb', line 46

def add(order)
  order.each { |position|
    add_position(position)
  }
end

#add_position(position) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/bbmb/html/state/history.rb', line 51

def add_position(position)
  key = position.article_number
  pos = @map.fetch(key) { 
    pos = @map.store(key, PositionFacade.new)
    @positions = @map.values
    pos
  }
  pos.add(position)
end

#each(&block) ⇒ Object



60
61
62
# File 'lib/bbmb/html/state/history.rb', line 60

def each(&block)
  @positions.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bbmb/html/state/history.rb', line 63

def empty?
  @positions.empty?
end

#reverse!Object



66
67
68
# File 'lib/bbmb/html/state/history.rb', line 66

def reverse!
  @positions.reverse!
end

#sort!(*args, &block) ⇒ Object



69
70
71
# File 'lib/bbmb/html/state/history.rb', line 69

def sort!(*args, &block)
  @positions.sort!(*args, &block)
end

#turnoverObject



72
73
74
75
76
# File 'lib/bbmb/html/state/history.rb', line 72

def turnover
  @positions.inject(0) { |inj, position| 
    position.total + inj
  }
end