Class: BillingLogic::Strategies::IndependentPaymentStrategy::ProductComparator
- Inherits:
-
Object
- Object
- BillingLogic::Strategies::IndependentPaymentStrategy::ProductComparator
- Extended by:
- Forwardable
- Defined in:
- lib/billing_logic/strategies/independent_payment_strategy.rb
Instance Method Summary collapse
- #in_class_of?(product_list) ⇒ Boolean
- #in_like?(product_list) ⇒ Boolean
- #included?(product_list) ⇒ Boolean
-
#initialize(product) ⇒ ProductComparator
constructor
A new instance of ProductComparator.
- #like?(other_product) ⇒ Boolean
- #same_class?(other_product) ⇒ Boolean
- #same_periodicity?(other_product) ⇒ Boolean
- #same_price?(other_product) ⇒ Boolean
- #similar?(other_product) ⇒ Boolean
Constructor Details
#initialize(product) ⇒ ProductComparator
Returns a new instance of ProductComparator.
279 280 281 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 279 def initialize(product) @product = product end |
Instance Method Details
#in_class_of?(product_list) ⇒ Boolean
287 288 289 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 287 def in_class_of?(product_list) product_list.any? { |product| ProductComparator.new(product).same_class?(self) } end |
#in_like?(product_list) ⇒ Boolean
291 292 293 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 291 def in_like?(product_list) product_list.any? { |product| ProductComparator.new(product).like?(self) } end |
#included?(product_list) ⇒ Boolean
283 284 285 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 283 def included?(product_list) product_list.any? { |product| ProductComparator.new(product).similar?(self) } end |
#like?(other_product) ⇒ Boolean
295 296 297 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 295 def like?(other_product) similar?(other_product) && same_periodicity?(other_product) end |
#same_class?(other_product) ⇒ Boolean
307 308 309 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 307 def same_class?(other_product) @product.name == other_product.name end |
#same_periodicity?(other_product) ⇒ Boolean
303 304 305 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 303 def same_periodicity?(other_product) @product.billing_cycle.periodicity == other_product.billing_cycle.periodicity end |
#same_price?(other_product) ⇒ Boolean
311 312 313 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 311 def same_price?(other_product) BigDecimal(@product.price.to_s) == BigDecimal(other_product.price.to_s) end |
#similar?(other_product) ⇒ Boolean
299 300 301 |
# File 'lib/billing_logic/strategies/independent_payment_strategy.rb', line 299 def similar?(other_product) same_class?(other_product) && same_price?(other_product) end |