Class: AppleBar

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ordergroup) ⇒ AppleBar

Returns a new instance of AppleBar.


5
6
7
8
9
# File 'lib/apple_bar.rb', line 5

def initialize(ordergroup)
  @ordergroup = ordergroup
  @group_avg = ordergroup.avg_jobs_per_euro.to_f
  @global_avg = Ordergroup.avg_jobs_per_euro
end

Instance Attribute Details

#ordergroupObject (readonly)

Returns the value of attribute ordergroup


3
4
5
# File 'lib/apple_bar.rb', line 3

def ordergroup
  @ordergroup
end

Instance Method Details

#applesObject


37
38
39
# File 'lib/apple_bar.rb', line 37

def apples
  @apples ||= @ordergroup.apples
end

#group_bar_stateObject

Show group bar in following colors: Green if higher than 100 Yellow if lower than 100 an higher than stop_ordering_under option value Red if below stop_ordering_under, the ordergroup isn't allowed to participate in an order anymore


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/apple_bar.rb', line 15

def group_bar_state
  if apples >= 100
    'success'
  else
    if FoodsoftConfig[:stop_ordering_under].present? and
        apples >= FoodsoftConfig[:stop_ordering_under]
      'warning'
    else
      'danger'
    end
  end
end

#group_bar_widthObject

Use apples as percentage, but show at least 10 percent


29
30
31
# File 'lib/apple_bar.rb', line 29

def group_bar_width
  @ordergroup.apples < 2 ? 2 : @ordergroup.apples
end

#mean_order_amount_per_jobObject


33
34
35
# File 'lib/apple_bar.rb', line 33

def mean_order_amount_per_job
  (1/@global_avg).round rescue 0
end

#with_restriction?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/apple_bar.rb', line 41

def with_restriction?
  FoodsoftConfig[:stop_ordering_under].present?
end