Class: AppleBar
- Inherits:
-
Object
- Object
- AppleBar
- Defined in:
- app/lib/apple_bar.rb
Instance Attribute Summary collapse
-
#ordergroup ⇒ Object
readonly
Returns the value of attribute ordergroup.
Instance Method Summary collapse
- #apples ⇒ Object
-
#group_bar_state ⇒ Object
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.
-
#group_bar_width ⇒ Object
Use apples as percentage, but show at least 10 percent.
-
#initialize(ordergroup) ⇒ AppleBar
constructor
A new instance of AppleBar.
- #mean_order_amount_per_job ⇒ Object
- #with_restriction? ⇒ Boolean
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
#ordergroup ⇒ Object (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
#apples ⇒ Object
36 37 38 |
# File 'app/lib/apple_bar.rb', line 36 def apples @apples ||= @ordergroup.apples end |
#group_bar_state ⇒ Object
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 if apples >= 100 'success' elsif FoodsoftConfig[:stop_ordering_under].present? && (apples >= FoodsoftConfig[:stop_ordering_under]) 'warning' else 'danger' end end |
#group_bar_width ⇒ Object
Use apples as percentage, but show at least 10 percent
26 27 28 |
# File 'app/lib/apple_bar.rb', line 26 def [@ordergroup.apples, 2].max end |
#mean_order_amount_per_job ⇒ Object
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
40 41 42 |
# File 'app/lib/apple_bar.rb', line 40 def with_restriction? FoodsoftConfig[:stop_ordering_under].present? end |