Class: Spree::GiftCard
- Inherits:
-
Object
- Object
- Spree::GiftCard
- Extended by:
- DisplayMoney
- Includes:
- Security::GiftCards, SingleStoreResource
- Defined in:
- app/models/spree/gift_card.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the gift card is active, i.e.
-
#amount=(amount) ⇒ Object
Sets the amount.
-
#amount_remaining ⇒ Decimal
Calculates the remaining amount.
-
#can_be_deleted? ⇒ Boolean
Checks if the gift card can be deleted.
-
#display_code ⇒ String
Displays the code in uppercase, eg.
-
#display_state ⇒ String
Displays state as expired if the gift card is expired, otherwise displays the state.
-
#editable? ⇒ Boolean
Checks if the gift card is editable.
-
#expired? ⇒ Boolean
Checks if the gift card is expired.
Methods included from DisplayMoney
Class Method Details
.json_api_columns ⇒ Object
88 89 90 |
# File 'app/models/spree/gift_card.rb', line 88 def self.json_api_columns %w[code amount expires_at] end |
Instance Method Details
#active? ⇒ Boolean
Checks if the gift card is active, i.e. not expired and not redeemed
118 119 120 |
# File 'app/models/spree/gift_card.rb', line 118 def active? super && !expired? end |
#amount=(amount) ⇒ Object
Sets the amount
76 77 78 |
# File 'app/models/spree/gift_card.rb', line 76 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#amount_remaining ⇒ Decimal
Calculates the remaining amount
82 83 84 |
# File 'app/models/spree/gift_card.rb', line 82 def amount_remaining amount - amount_used - end |
#can_be_deleted? ⇒ Boolean
Checks if the gift card can be deleted
100 101 102 |
# File 'app/models/spree/gift_card.rb', line 100 def can_be_deleted? !redeemed? && !partially_redeemed? end |
#display_code ⇒ String
Displays the code in uppercase, eg. ABC1234
106 107 108 |
# File 'app/models/spree/gift_card.rb', line 106 def display_code code.upcase end |
#display_state ⇒ String
Displays state as expired if the gift card is expired, otherwise displays the state
124 125 126 127 128 129 130 |
# File 'app/models/spree/gift_card.rb', line 124 def display_state if expired? :expired else state end.to_s end |
#editable? ⇒ Boolean
Checks if the gift card is editable
94 95 96 |
# File 'app/models/spree/gift_card.rb', line 94 def editable? active? end |
#expired? ⇒ Boolean
Checks if the gift card is expired
112 113 114 |
# File 'app/models/spree/gift_card.rb', line 112 def expired? !redeemed? && expires_at.present? && expires_at <= Date.current end |