Sha256: fd4db3d7f771675dc2564774a5034ee1ed4ab734098fd9b108f09fad5d04a604

Contents?: true

Size: 619 Bytes

Versions: 1

Compression:

Stored size: 619 Bytes

Contents

# frozen_string_literal: true

module GraphTypes
  MoneyType = ::GraphQL::ObjectType.define do
    name 'MoneyType'

    field :cents, types.Int do
      resolve ->(object, _args, _context) do
        (object.to_f * 100).to_i
      end
    end

    field :formatted, types.String do
      argument :delimiter, types.String, default_value: '.'
      argument :separator, types.String, default_value: ','
      argument :unit,      types.String, default_value: 'R$ '

      resolve ->(object, args, _context) do
        ActionController::Base.helpers.number_to_currency object.to_f, args.to_h
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graph_types-0.1.0 lib/graph_types/money_type.rb