Class: AppleBar

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ordergroup) ⇒ AppleBar

Returns a new instance of AppleBar.



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

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.



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

def ordergroup
  @ordergroup
end

Instance Method Details

#applesObject



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

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



14
15
16
17
18
19
20
21
22
23
# File 'app/lib/apple_bar.rb', line 14

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

#group_bar_widthObject

Use apples as percentage, but show at least 10 percent



26
27
28
# File 'app/lib/apple_bar.rb', line 26

def group_bar_width
  [@ordergroup.apples, 2].max
end

#mean_order_amount_per_jobObject



30
31
32
33
34
# File 'app/lib/apple_bar.rb', line 30

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

#with_restriction?Boolean

Returns:

  • (Boolean)


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

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