Class: Metanorma::Mirror::Model::Mark
- Inherits:
-
Object
- Object
- Metanorma::Mirror::Model::Mark
- Defined in:
- lib/metanorma/mirror/model/mark.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #fetch(key, default = nil) ⇒ Object
-
#initialize(type:, attrs: {}) ⇒ Mark
constructor
A new instance of Mark.
- #set_attr(key, value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(type:, attrs: {}) ⇒ Mark
Returns a new instance of Mark.
9 10 11 12 |
# File 'lib/metanorma/mirror/model/mark.rb', line 9 def initialize(type:, attrs: {}) @type = type @attrs = normalize_attrs(attrs) end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
7 8 9 |
# File 'lib/metanorma/mirror/model/mark.rb', line 7 def attrs @attrs end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/metanorma/mirror/model/mark.rb', line 7 def type @type end |
Class Method Details
.from_h(hash) ⇒ Object
37 38 39 40 41 |
# File 'lib/metanorma/mirror/model/mark.rb', line 37 def self.from_h(hash) return nil unless hash new(type: hash["type"], attrs: hash["attrs"] || {}) end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/metanorma/mirror/model/mark.rb', line 20 def [](key) @attrs[key.to_s] end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/metanorma/mirror/model/mark.rb', line 24 def []=(key, value) @attrs[key.to_s] = value end |
#fetch(key, default = nil) ⇒ Object
33 34 35 |
# File 'lib/metanorma/mirror/model/mark.rb', line 33 def fetch(key, default = nil, &) @attrs.fetch(key.to_s, default, &) end |
#set_attr(key, value) ⇒ Object
28 29 30 31 |
# File 'lib/metanorma/mirror/model/mark.rb', line 28 def set_attr(key, value) @attrs[key.to_s] = value self end |
#to_h ⇒ Object
14 15 16 17 18 |
# File 'lib/metanorma/mirror/model/mark.rb', line 14 def to_h h = { "type" => type } h["attrs"] = @attrs.dup unless @attrs.empty? h end |