Class: ActsAsCalculator::Tier
- Inherits:
-
Data
- Object
- Data
- ActsAsCalculator::Tier
- Defined in:
- lib/acts_as_calculator/tier.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from
4 5 6 |
# File 'lib/acts_as_calculator/tier.rb', line 4 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to
4 5 6 |
# File 'lib/acts_as_calculator/tier.rb', line 4 def to @to end |
#value ⇒ Object (readonly)
Returns the value of attribute value
4 5 6 |
# File 'lib/acts_as_calculator/tier.rb', line 4 def value @value end |
Class Method Details
.build(source) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/acts_as_calculator/tier.rb', line 5 def self.build(source) return source if source.is_a?(Tier) attributes = source.respond_to?(:to_h) ? source.to_h : read_from(source) attributes = attributes.transform_keys(&:to_sym) new(from: attributes[:from], to: attributes[:to], value: attributes[:value]) end |
Instance Method Details
#covers?(amount) ⇒ Boolean
19 20 21 |
# File 'lib/acts_as_calculator/tier.rb', line 19 def covers?(amount) amount >= lower_bound && amount < upper_bound end |
#lower_bound ⇒ Object
23 24 25 |
# File 'lib/acts_as_calculator/tier.rb', line 23 def lower_bound from || -Float::INFINITY end |
#upper_bound ⇒ Object
27 28 29 |
# File 'lib/acts_as_calculator/tier.rb', line 27 def upper_bound to || Float::INFINITY end |