Sha256: 836fdf364c10399d01aa1c4eaa5fa5ac349b48ca37859b02022dafd966c08b7b

Contents?: true

Size: 776 Bytes

Versions: 14

Compression:

Stored size: 776 Bytes

Contents

# frozen_string_literal: true

require 'pi_resources/serializer/object_serializer'

module PiResources
  module Serializer
    class MoneySerializer
      include ObjectSerializer

      attribute :cents, method: :cents
      attribute :amount, method: :amount
      attribute :currency, method: :currency
      attribute :formatted_text, method: :formatted_text
      attribute :symbol, method: :symbol

      def cents(record)
        record.cents
      end

      def amount(record)
        record.to_f
      end

      def currency(record)
        record.currency.iso_code
      end

      def formatted_text(record)
        record.format(symbol: "#{record.currency.symbol} ")
      end

      def symbol(record)
        record.currency.symbol
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pi-resources-rails-0.6.3 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.6.2 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.6.1 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.6.0 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.5.0 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.4.4 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.4.3 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.4.2 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.4.1 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.4.0 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.3.0 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.2.0 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.1.1 lib/pi_resources/serializer/money_serializer.rb
pi-resources-rails-0.1.0 lib/pi_resources/serializer/money_serializer.rb