Class: ConservationGuardian::Budget
- Inherits:
-
Object
- Object
- ConservationGuardian::Budget
- Defined in:
- lib/conservation_guardian/budget.rb
Instance Attribute Summary collapse
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #categories ⇒ Object
- #exceeded?(category, value) ⇒ Boolean
-
#initialize(name: "default", limits: {}) ⇒ Budget
constructor
limits: Hash of { category_name => max_value }.
- #limit_for(category) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name: "default", limits: {}) ⇒ Budget
limits: Hash of { category_name => max_value }
8 9 10 11 12 |
# File 'lib/conservation_guardian/budget.rb', line 8 def initialize(name: "default", limits: {}) @name = name @limits = limits.transform_keys(&:to_sym) freeze end |
Instance Attribute Details
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
5 6 7 |
# File 'lib/conservation_guardian/budget.rb', line 5 def limits @limits end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/conservation_guardian/budget.rb', line 5 def name @name end |
Instance Method Details
#categories ⇒ Object
25 26 27 |
# File 'lib/conservation_guardian/budget.rb', line 25 def categories @limits.keys end |
#exceeded?(category, value) ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/conservation_guardian/budget.rb', line 18 def exceeded?(category, value) max = limit_for(category) return false if max.nil? value > max end |
#limit_for(category) ⇒ Object
14 15 16 |
# File 'lib/conservation_guardian/budget.rb', line 14 def limit_for(category) @limits[category.to_sym] end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/conservation_guardian/budget.rb', line 29 def to_h { name: @name, limits: @limits.dup } end |