module Money::Currency::Converter

Overview

Currency converter to be used with JSON and YAML serialization.

require "json"
require "yaml"

record FooWithCurrency, currency : Money::Currency do
  include JSON::Serializable
  include YAML::Serializable

  @[JSON::Field(converter: Money::Currency::Converter)]
  @[YAML::Field(converter: Money::Currency::Converter)]
  @currency : Money::Currency
end

foo = FooWithCurrency.new(Money::Currency.find("USD"))
foo.to_json # => "{\"currency\":\"USD\"}"
foo.to_yaml # => "currency: USD"

Extended Modules

Defined in:

money/currency/converter.cr

Instance Method Summary

Instance Method Detail

def from_json(pull : JSON::PullParser) : Currency #

[View source]
def from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Currency #

[View source]
def to_json(currency : Currency, json : JSON::Builder) #

[View source]
def to_yaml(currency : Currency, yaml : YAML::Nodes::Builder) #

[View source]