Class: LoyaltyProgram::Qualification
- Inherits:
-
Object
- Object
- LoyaltyProgram::Qualification
- Defined in:
- app/my_lib/loyalty_program/qualification.rb
Overview
Check and update qualification progress data and update user loyalty level after reservation mark as arrived/delivered
Instance Attribute Summary collapse
-
#next_tier ⇒ Object
Returns the value of attribute next_tier.
-
#reservation ⇒ Object
Returns the value of attribute reservation.
-
#user_loyalty ⇒ Object
Returns the value of attribute user_loyalty.
Instance Method Summary collapse
-
#initialize(user_loyalty, reservation = nil) ⇒ Qualification
constructor
A new instance of Qualification.
-
#qualified_to_upgrade?(next_tier = nil) ⇒ Boolean
check if user qualified to upgrade or regain.
-
#update_data_and_set_tier! ⇒ UserLoyalty
update data and set user loyalty level.
Constructor Details
#initialize(user_loyalty, reservation = nil) ⇒ Qualification
Returns a new instance of Qualification.
9 10 11 12 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 9 def initialize(user_loyalty, reservation = nil) @user_loyalty = user_loyalty @reservation = reservation end |
Instance Attribute Details
#next_tier ⇒ Object
Returns the value of attribute next_tier.
5 6 7 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 5 def next_tier @next_tier end |
#reservation ⇒ Object
Returns the value of attribute reservation.
5 6 7 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 5 def reservation @reservation end |
#user_loyalty ⇒ Object
Returns the value of attribute user_loyalty.
5 6 7 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 5 def user_loyalty @user_loyalty end |
Instance Method Details
#qualified_to_upgrade?(next_tier = nil) ⇒ Boolean
check if user qualified to upgrade or regain
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 29 def qualified_to_upgrade?(next_tier = nil) @next_tier = if next_tier.present? next_tier else current_tier = user_loyalty.state.to_sym current_rank = UserLoyalty::LOYALTY_SCORE[current_tier] next_rank = current_rank + 1 UserLoyalty::LOYALTY_SCORE.invert[next_rank] || UserLoyalty::LOYALTY_SCORE.invert[UserLoyalty::LOYALTY_SCORE.invert.keys.max] end return true if valid_qualification_requirement? return true if valid_tier_regain_requirement? false end |
#update_data_and_set_tier! ⇒ UserLoyalty
update data and set user loyalty level
17 18 19 20 21 22 23 24 |
# File 'app/my_lib/loyalty_program/qualification.rb', line 17 def update_data_and_set_tier! update_progress_data! verify_level_and_upgrade! maintenance_higest_tier! user_loyalty.reload end |