Class: Membership

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Summary collapse

Methods included from Extendable

#adjust_expiration_to

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_feeObject



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

Returns:

  • (Boolean)


44
45
46
# File 'app/models/membership.rb', line 44

def changed?
  self.changed_to.present?
end

#changee?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/membership.rb', line 48

def changee?
  self.changed_membership.present?
end

#exchangeable?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/membership.rb', line 89

def exchangeable?
  false
end

#expired?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/models/membership.rb', line 81

def expired?
  ends_at < Time.now
end

#itemObject



56
57
58
# File 'app/models/membership.rb', line 56

def item
  items.first
end

#order_summary_descriptionObject



97
98
99
# File 'app/models/membership.rb', line 97

def order_summary_description
  self.membership_type.name
end

#realized_feeObject



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

Returns:

  • (Boolean)


85
86
87
# File 'app/models/membership.rb', line 85

def refundable?
  true
end

#returnable?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/models/membership.rb', line 93

def returnable?
  false
end

#update_member_countersObject



52
53
54
# File 'app/models/membership.rb', line 52

def update_member_counters
  self.member.try(:count_memberships)
end