Class: Field

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



2518
2519
2520
2521
2522
2523
2524
2525
2526
# File 'lib/schemas.rb', line 2518

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    linked_id:  d["linkedId"],
    field_name: d["name"],
    field_type: d.fetch("type"),
    value:      d["value"],
  )
end

.from_json!(json) ⇒ Object



2528
2529
2530
# File 'lib/schemas.rb', line 2528

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

Instance Method Details

#to_dynamicObject



2532
2533
2534
2535
2536
2537
2538
2539
# File 'lib/schemas.rb', line 2532

def to_dynamic
  {
    "linkedId" => linked_id,
    "name"     => field_name,
    "type"     => field_type,
    "value"    => value,
  }
end

#to_json(options = nil) ⇒ Object



2541
2542
2543
# File 'lib/schemas.rb', line 2541

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