Class: Ortfodb::Tag

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

Overview

Tag represents a category that can be assigned to a work.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ortfodb/tags.rb', line 76

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    aliases:       d["aliases"],
    description:   d["description"],
    detect:        d["detect"] ? Detect.from_dynamic!(d["detect"]) : nil,
    learn_more_at: d["learn more at"],
    plural:        d.fetch("plural"),
    singular:      d.fetch("singular"),
  )
end

.from_json!(json) ⇒ Object



88
89
90
# File 'lib/ortfodb/tags.rb', line 88

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

Instance Method Details

#to_dynamicObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/ortfodb/tags.rb', line 92

def to_dynamic
  {
    "aliases"       => aliases,
    "description"   => description,
    "detect"        => detect&.to_dynamic,
    "learn more at" => learn_more_at,
    "plural"        => plural,
    "singular"      => singular,
  }
end

#to_json(options = nil) ⇒ Object



103
104
105
# File 'lib/ortfodb/tags.rb', line 103

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