Class: PlanFeatures::Pricing
- Inherits:
-
Object
- Object
- PlanFeatures::Pricing
- Includes:
- ActiveModel::Model
- Defined in:
- lib/plan_features/pricing.rb
Instance Attribute Summary collapse
-
#features ⇒ Object
Returns the value of attribute features.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plan_identifier ⇒ Object
Returns the value of attribute plan_identifier.
-
#popular ⇒ Object
Returns the value of attribute popular.
-
#previous ⇒ Object
Returns the value of attribute previous.
-
#prices ⇒ Object
Returns the value of attribute prices.
-
#stripe_id ⇒ Object
Returns the value of attribute stripe_id.
Class Method Summary collapse
- .all_plans ⇒ Object
- .boosts ⇒ Object
- .find_by_identifier(id) ⇒ Object
- .find_by_pricing_id(id, interval: "monthly") ⇒ Object
- .free_plan ⇒ Object
Instance Method Summary collapse
- #current_and_previous_features ⇒ Object
- #display_features ⇒ Object
- #free? ⇒ Boolean
- #has_feature?(feature, id: nil) ⇒ Boolean
- #limit_for(feature) ⇒ Object
- #paid? ⇒ Boolean
- #previous_features ⇒ Object
- #previous_plan ⇒ Object
- #price(name: :monthly) ⇒ Object
- #pricing_id(name: :monthly) ⇒ Object
- #yearly_price_monthly ⇒ Object
Instance Attribute Details
#features ⇒ Object
Returns the value of attribute features.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def features @features end |
#interval ⇒ Object
Returns the value of attribute interval.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def interval @interval end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def name @name end |
#plan_identifier ⇒ Object
Returns the value of attribute plan_identifier.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def plan_identifier @plan_identifier end |
#popular ⇒ Object
Returns the value of attribute popular.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def popular @popular end |
#previous ⇒ Object
Returns the value of attribute previous.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def previous @previous end |
#prices ⇒ Object
Returns the value of attribute prices.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def prices @prices end |
#stripe_id ⇒ Object
Returns the value of attribute stripe_id.
5 6 7 |
# File 'lib/plan_features/pricing.rb', line 5 def stripe_id @stripe_id end |
Class Method Details
.all_plans ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/plan_features/pricing.rb', line 28 def self.all_plans @all_plans ||= YAML.load_file(::PlanFeatures.configuration.plans_file_path).map do |plan, attributes| Pricing.new( plan_identifier: plan, popular: attributes["popular"], name: attributes["name"], features: attributes["features"], prices: attributes["prices"], previous: attributes["previous"] ) end end |
.boosts ⇒ Object
9 10 11 12 13 |
# File 'lib/plan_features/pricing.rb', line 9 def self.boosts @boosts ||= if File.exist?(Rails.root.join("config", "account_boosts.yml")) YAML.load_file(Rails.root.join("config", "account_boosts.yml")) end end |
.find_by_identifier(id) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/plan_features/pricing.rb', line 15 def self.find_by_identifier(id) plan = Pricing.all_plans.find { |plan| plan.plan_identifier == id.to_s } raise "Plan not found" if plan.nil? plan end |
Instance Method Details
#current_and_previous_features ⇒ Object
45 46 47 |
# File 'lib/plan_features/pricing.rb', line 45 def current_and_previous_features features.merge(previous_features) end |
#display_features ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/plan_features/pricing.rb', line 92 def display_features features.map do |identifier, attributes| PricingFeatures::Feature.new( identifier: identifier, description: attributes["description"], limit: attributes["limit"], hidden: attributes["hidden"] ) end.compact.filter { |f| !f.hidden? } end |
#free? ⇒ Boolean
69 70 71 |
# File 'lib/plan_features/pricing.rb', line 69 def free? prices.nil? end |
#has_feature?(feature, id: nil) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/plan_features/pricing.rb', line 49 def has_feature?(feature, id: nil) return true if Pricing.boosts&.[](id)&.include?(feature.to_s) current_and_previous_features.find { |f| f[0] == feature.to_s }.present? end |
#limit_for(feature) ⇒ Object
65 66 67 |
# File 'lib/plan_features/pricing.rb', line 65 def limit_for(feature) features.dig(feature.to_s, "limit") end |
#paid? ⇒ Boolean
73 74 75 |
# File 'lib/plan_features/pricing.rb', line 73 def paid? prices&.any? end |
#previous_features ⇒ Object
55 56 57 |
# File 'lib/plan_features/pricing.rb', line 55 def previous_features previous_plan&.current_and_previous_features || {} end |
#previous_plan ⇒ Object
59 60 61 62 63 |
# File 'lib/plan_features/pricing.rb', line 59 def previous_plan Pricing.all_plans.find do |plan| plan.plan_identifier == previous end end |
#price(name: :monthly) ⇒ Object
82 83 84 85 |
# File 'lib/plan_features/pricing.rb', line 82 def price(name: :monthly) return nil if prices.nil? prices[name.to_s]["amount"] / 100 end |
#pricing_id(name: :monthly) ⇒ Object
77 78 79 80 |
# File 'lib/plan_features/pricing.rb', line 77 def pricing_id(name: :monthly) return nil if prices.nil? prices[name.to_s]["product"] end |
#yearly_price_monthly ⇒ Object
87 88 89 90 |
# File 'lib/plan_features/pricing.rb', line 87 def yearly_price_monthly return nil if prices.nil? (prices["yearly"]["amount"].to_f / 100 / 12).round(2) end |