Class: Card

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schemas.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
# File 'lib/schemas.rb', line 2437

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    brand:           d["brand"],
    cardholder_name: d["cardholderName"],
    code:            d["code"],
    exp_month:       d["expMonth"],
    exp_year:        d["expYear"],
    number:          d["number"],
  )
end

.from_json!(json) ⇒ Object



2449
2450
2451
# File 'lib/schemas.rb', line 2449

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

Instance Method Details

#to_dynamicObject



2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
# File 'lib/schemas.rb', line 2453

def to_dynamic
  {
    "brand"          => brand,
    "cardholderName" => cardholder_name,
    "code"           => code,
    "expMonth"       => exp_month,
    "expYear"        => exp_year,
    "number"         => number,
  }
end

#to_json(options = nil) ⇒ Object



2464
2465
2466
# File 'lib/schemas.rb', line 2464

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