Sha256: 59b2c36b7bc6e326c285ef609d5a17bb63bfcdab924c2fe8d77871698daf586b

Contents?: true

Size: 828 Bytes

Versions: 4

Compression:

Stored size: 828 Bytes

Contents

# frozen_string_literal: true

module SolidusVolumePricing
  class PriceDisplay
    attr_reader :variant, :quantity, :user

    def initialize(variant, quantity: 1, user: nil)
      @variant = variant
      @quantity = quantity
      @user = user
    end

    def price_string
      price.to_s
    end

    def earning_amount_string
      earning_amount.to_s
    end

    def earning_percent_string
      earning_percent.to_s
    end

    private

    def price
      pricer.price_for(options)
    end

    def earning_amount
      pricer.earning_amount(options)
    end

    def earning_percent
      pricer.earning_percent(options)
    end

    def options
      SolidusVolumePricing::PricingOptions.new(quantity: quantity, user: user)
    end

    def pricer
      SolidusVolumePricing::Pricer.new(variant)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_volume_pricing-1.2.0 app/models/solidus_volume_pricing/price_display.rb
solidus_volume_pricing-1.1.1 app/models/solidus_volume_pricing/price_display.rb
solidus_volume_pricing-1.1.0 app/models/solidus_volume_pricing/price_display.rb
solidus_volume_pricing-1.0.0 app/models/solidus_volume_pricing/price_display.rb