Class: Glossarist::Citation
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Glossarist::Citation
- Defined in:
- lib/glossarist/citation.rb
Instance Method Summary collapse
-
#clause_from_yaml(model, value) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#clause_to_yaml(model, doc) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#id ⇒ String
Document ID in structured reference.
- #id_from_yaml(model, value) ⇒ Object
- #id_to_yaml(_model, _doc) ⇒ Object
-
#link ⇒ String
Link to document.
-
#locality ⇒ String
Referred locality of the document.
-
#original ⇒ String
Original ref text before parsing.
- #plain? ⇒ Boolean
- #ref=(ref) ⇒ Object
- #ref_from_yaml(model, value) ⇒ Object
- #ref_hash(model = self) ⇒ Object
- #ref_to_yaml(model, doc) ⇒ Object
-
#source ⇒ String
Source in structured reference.
- #source_from_yaml(model, value) ⇒ Object
- #source_to_yaml(_model, _doc) ⇒ Object
-
#structured? ⇒ Boolean
Whether it is a structured ref.
-
#text ⇒ String
Unstructured (plain text) reference.
- #text_from_yaml(model, value) ⇒ Object
- #text_to_yaml(_model, _doc) ⇒ Object
-
#version ⇒ String
Document version in structured reference.
- #version_from_yaml(model, value) ⇒ Object
- #version_to_yaml(_model, _doc) ⇒ Object
Instance Method Details
#clause_from_yaml(model, value) ⇒ Object
rubocop:disable Metrics/AbcSize
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/glossarist/citation.rb', line 115 def clause_from_yaml(model, value) # rubocop:disable Metrics/AbcSize # accepts old format like # clause: "11" # or new format like # locality: { type: "clause", reference_from: "11", reference_to: "12" } locality = Locality.new if value.is_a?(Hash) locality.type = value["type"] || "clause" locality.reference_from = value["reference_from"] || value locality.reference_to = value["reference_to"] if value["reference_to"] else locality.type = "clause" locality.reference_from = value end locality.validate! model.locality = locality end |
#clause_to_yaml(model, doc) ⇒ Object
rubocop:disable Metrics/AbcSize
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/glossarist/citation.rb', line 135 def clause_to_yaml(model, doc) # rubocop:disable Metrics/AbcSize if model.locality doc["locality"] = {} doc["locality"]["type"] = model.locality.type if model.locality.reference_from doc["locality"]["reference_from"] = model.locality.reference_from end if model.locality.reference_to doc["locality"]["reference_to"] = model.locality.reference_to end end end |
#id ⇒ String
Document ID in structured reference.
13 |
# File 'lib/glossarist/citation.rb', line 13 attribute :id, :string |
#id_from_yaml(model, value) ⇒ Object
65 66 67 |
# File 'lib/glossarist/citation.rb', line 65 def id_from_yaml(model, value) model.id = value end |
#id_to_yaml(_model, _doc) ⇒ Object
69 70 71 |
# File 'lib/glossarist/citation.rb', line 69 def id_to_yaml(_model, _doc) # skip, will be handled in ref end |
#link ⇒ String
Link to document.
25 |
# File 'lib/glossarist/citation.rb', line 25 attribute :link, :string |
#locality ⇒ String
Referred locality of the document.
21 |
# File 'lib/glossarist/citation.rb', line 21 attribute :locality, Locality |
#original ⇒ String
This attribute is likely to be removed or reworked in future. It is arguably not relevant to Glossarist itself.
Original ref text before parsing.
31 |
# File 'lib/glossarist/citation.rb', line 31 attribute :original, :string |
#plain? ⇒ Boolean
150 151 152 |
# File 'lib/glossarist/citation.rb', line 150 def plain? (source && id && version).nil? end |
#ref=(ref) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/glossarist/citation.rb', line 105 def ref=(ref) if ref.is_a?(Hash) @source = ref["source"] @id = ref["id"] @version = ref["version"] else @text = ref end end |
#ref_from_yaml(model, value) ⇒ Object
53 54 55 |
# File 'lib/glossarist/citation.rb', line 53 def ref_from_yaml(model, value) model.ref = value end |
#ref_hash(model = self) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/glossarist/citation.rb', line 97 def ref_hash(model = self) { "source" => model.source, "id" => model.id, "version" => model.version, }.compact end |
#ref_to_yaml(model, doc) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/glossarist/citation.rb', line 57 def ref_to_yaml(model, doc) doc["ref"] = if model.structured? ref_hash(model) else model.text end end |
#source ⇒ String
Source in structured reference.
9 |
# File 'lib/glossarist/citation.rb', line 9 attribute :source, :string |
#source_from_yaml(model, value) ⇒ Object
81 82 83 |
# File 'lib/glossarist/citation.rb', line 81 def source_from_yaml(model, value) model.source = value end |
#source_to_yaml(_model, _doc) ⇒ Object
85 86 87 |
# File 'lib/glossarist/citation.rb', line 85 def source_to_yaml(_model, _doc) # skip, will be handled in ref end |
#structured? ⇒ Boolean
Whether it is a structured ref.
156 157 158 |
# File 'lib/glossarist/citation.rb', line 156 def structured? !plain? end |
#text ⇒ String
Unstructured (plain text) reference.
5 |
# File 'lib/glossarist/citation.rb', line 5 attribute :text, :string |
#text_from_yaml(model, value) ⇒ Object
73 74 75 |
# File 'lib/glossarist/citation.rb', line 73 def text_from_yaml(model, value) model.text = value end |
#text_to_yaml(_model, _doc) ⇒ Object
77 78 79 |
# File 'lib/glossarist/citation.rb', line 77 def text_to_yaml(_model, _doc) # skip, will be handled in ref end |
#version ⇒ String
Document version in structured reference.
17 |
# File 'lib/glossarist/citation.rb', line 17 attribute :version, :string |
#version_from_yaml(model, value) ⇒ Object
89 90 91 |
# File 'lib/glossarist/citation.rb', line 89 def version_from_yaml(model, value) model.version = value end |
#version_to_yaml(_model, _doc) ⇒ Object
93 94 95 |
# File 'lib/glossarist/citation.rb', line 93 def version_to_yaml(_model, _doc) # skip, will be handled in ref end |