Sha256: 10965c35f5bdf05104ad1de7653fe8d3632b9ed38590c70a935eb2e958fc5165

Contents?: true

Size: 1.83 KB

Versions: 19

Compression:

Stored size: 1.83 KB

Contents

module Centaman
  class Object::Extra < Centaman::Object
    attr_reader :booking_time_id
    attr_accessor :quantity

    def after_init(args = {})
      @quantity = 0
      @booking_time_id = args.fetch(:booking_time_id, nil)
    end

    def price
      @price ||= tax_inclusive ? calculate_price_before_tax : price_including_tax
    end

    def calculate_price_before_tax
      p = price_including_tax / (1 + tax_percentage / 100)
      p.round(2)
    end

    def json
      {
        id: id,
        description: description,
        quantity: quantity,
        price: price,
        deposit_percentage: deposit_percentage,
        tax_inclusive: tax_inclusive,
        tax_percentage: tax_percentage
      }
    end

    def description
      @extra_description.gsub!('Bar Package Cocktail Cruises', 'Bar Package')
      @description = @extra_description
    end

    # rubocop:disable Metrics/MethodLength
    def attributes
      [
        Centaman::Attribute.new(
          centaman_key: 'ExtraId',
          app_key: :id,
          type: :integer
        ),
        Centaman::Attribute.new(
          centaman_key: 'ExtraDescription',
          app_key: :extra_description,
          type: :string
        ),
        Centaman::Attribute.new(
          centaman_key: 'ExtraPrice',
          app_key: :price_including_tax,
          type: :float
        ),
        Centaman::Attribute.new(
          centaman_key: 'DepositPercentage',
          app_key: :deposit_percentage,
          type: :float
        ),
        Centaman::Attribute.new(
          centaman_key: 'IsTaxInclusive',
          app_key: :tax_inclusive,
          type: :boolean
        ),
        Centaman::Attribute.new(
          centaman_key: 'TaxPercentage',
          app_key: :tax_percentage,
          type: :float
        )
      ]
    end
    # rubocop:enable Metrics/MethodLength
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
centaman-8.0.0 lib/centaman/object/extra.rb
centaman-7.0.5 lib/centaman/object/extra.rb
centaman-7.0.4 lib/centaman/object/extra.rb
centaman-7.0.3 lib/centaman/object/extra.rb
centaman-7.0.2 lib/centaman/object/extra.rb
centaman-7.0.1 lib/centaman/object/extra.rb
centaman-7.0.0 lib/centaman/object/extra.rb
centaman-6.0.8 lib/centaman/object/extra.rb
centaman-6.0.7 lib/centaman/object/extra.rb
centaman-6.0.5 lib/centaman/object/extra.rb
centaman-6.0.4 lib/centaman/object/extra.rb
centaman-6.0.3 lib/centaman/object/extra.rb
centaman-6.0.2 lib/centaman/object/extra.rb
centaman-6.0.1 lib/centaman/object/extra.rb
centaman-6.0.0 lib/centaman/object/extra.rb
centaman-5.0.8 lib/centaman/object/extra.rb
centaman-5.0.7 lib/centaman/object/extra.rb
centaman-5.0.6 lib/centaman/object/extra.rb
centaman-5.0.5 lib/centaman/object/extra.rb