Class: DdbRuby::FifthEdition::Currencies

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/ddb_ruby/fifth_edition/structs.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2933

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    cp: d.fetch("cp"),
    sp: d.fetch("sp"),
    gp: d.fetch("gp"),
    ep: d.fetch("ep"),
    pp: d.fetch("pp"),
  )
end

.from_json!(json) ⇒ Object



2944
2945
2946
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2944

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



2948
2949
2950
2951
2952
2953
2954
2955
2956
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2948

def to_dynamic
  {
    "cp" => cp,
    "sp" => sp,
    "gp" => gp,
    "ep" => ep,
    "pp" => pp,
  }
end

#to_json(options = nil) ⇒ Object



2958
2959
2960
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2958

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end