Module: Discounter

Defined in:
lib/discounter.rb,
lib/discounter/version.rb

Overview

We expect the entity to have a price attribute.

Constant Summary collapse

VERSION =
"0.0.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.priceObject

Returns the value of attribute price.



8
9
10
# File 'lib/discounter.rb', line 8

def price
  @price
end

Class Method Details

.evaluate_discount(user, join) ⇒ Object

User is the user that may have a discount for this entity. Join is the entity in which there is a setting for yes this user has a discount associated to them. We expect the join model to have a discount_tier column that is set to either. So we expect it to be set up this way:

  • Model Join - Attributes: user_id, discount_tier (optional column = entity_id (for discounting on)).

nil if there is no discount, or the discount tier if there is indeed one.



27
28
29
# File 'lib/discounter.rb', line 27

def evaluate_discount(user, join)
  Join.find_all_by_user_id(user.id).each(&method(:verify_discount_applicability))
end

.initialize(entity) ⇒ Object

Entity is the entity in which the price to be set is on.



11
12
13
14
# File 'lib/discounter.rb', line 11

def initialize(entity)
  @entity ||= entity
  @price  ||= entity.try(:price)
end

.initialize_discountObject



16
17
18
# File 'lib/discounter.rb', line 16

def initialize_discount 
  # ?
end