Class: Membership
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Membership
- Includes:
- Extendable
- Defined in:
- app/models/membership.rb
Overview
service_fee represents the fee displayed to the patron in the cart. If the producer is eating the fee, service_fee is 0
Class Method Summary collapse
- .for(membership_type, member = nil) ⇒ Object
- .realized_fee ⇒ Object
- .to_sentence(memberships) ⇒ Object
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #changee? ⇒ Boolean
- #exchangeable? ⇒ Boolean
- #expired? ⇒ Boolean
- #item ⇒ Object
- #order_summary_description ⇒ Object
- #realized_fee ⇒ Object
- #refundable? ⇒ Boolean
- #returnable? ⇒ Boolean
- #update_member_counters ⇒ Object
Methods included from Extendable
Class Method Details
.for(membership_type, member = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/membership.rb', line 31 def self.for(membership_type, member = nil) new.tap do |membership| membership.membership_type = membership_type membership.organization = membership_type.organization membership.price = membership_type.price_for(member) membership.cart_price = membership.price membership.sold_price = membership.price membership.total_paid = membership.price membership.starts_at = membership_type.starts_at membership.ends_at = membership_type.ends_at end end |
.realized_fee ⇒ Object
60 61 62 |
# File 'app/models/membership.rb', line 60 def self.realized_fee 0 end |
.to_sentence(memberships) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/membership.rb', line 68 def self.to_sentence(memberships) if memberships.any? membership_types = memberships.collect(&:membership_type).uniq if membership_types.length > 1 "multiple memberships" else ActionController::Base.helpers.pluralize(memberships.length, "#{memberships.first.membership_type.membershipize}") end else "No memberships" end end |
Instance Method Details
#changed? ⇒ Boolean
44 45 46 |
# File 'app/models/membership.rb', line 44 def changed? self.changed_to.present? end |
#changee? ⇒ Boolean
48 49 50 |
# File 'app/models/membership.rb', line 48 def changee? self.changed_membership.present? end |
#exchangeable? ⇒ Boolean
89 90 91 |
# File 'app/models/membership.rb', line 89 def exchangeable? false end |
#expired? ⇒ Boolean
81 82 83 |
# File 'app/models/membership.rb', line 81 def expired? ends_at < Time.now end |
#item ⇒ Object
56 57 58 |
# File 'app/models/membership.rb', line 56 def item items.first end |
#order_summary_description ⇒ Object
97 98 99 |
# File 'app/models/membership.rb', line 97 def order_summary_description self.membership_type.name end |
#realized_fee ⇒ Object
64 65 66 |
# File 'app/models/membership.rb', line 64 def realized_fee self.membership_type.hide_fee? ? self.cart_price * MembershipType::SERVICE_FEE : 0 end |
#refundable? ⇒ Boolean
85 86 87 |
# File 'app/models/membership.rb', line 85 def refundable? true end |
#returnable? ⇒ Boolean
93 94 95 |
# File 'app/models/membership.rb', line 93 def returnable? false end |
#update_member_counters ⇒ Object
52 53 54 |
# File 'app/models/membership.rb', line 52 def update_member_counters self.member.try(:count_memberships) end |