Class: Glossarist::Citation
Instance Attribute Summary collapse
-
#clause ⇒ String
Referred clause of the document.
-
#id ⇒ String
Document ID in structured reference.
-
#link ⇒ String
Link to document.
-
#original ⇒ String
Original ref text before parsing.
-
#source ⇒ String
Source in structured reference.
-
#text ⇒ String
Unstructured (plain text) reference.
-
#version ⇒ String
Document version in structured reference.
Class Method Summary collapse
Instance Method Summary collapse
-
#plain? ⇒ Boolean
Whether it is a plain text ref.
- #ref=(ref) ⇒ Object
-
#structured? ⇒ Boolean
Whether it is a structured ref.
- #to_h ⇒ Object
Methods inherited from Model
#initialize, new, #set_attribute
Constructor Details
This class inherits a constructor from Glossarist::Model
Instance Attribute Details
#clause ⇒ String
Referred clause of the document.
26 27 28 |
# File 'lib/glossarist/citation.rb', line 26 def clause @clause end |
#id ⇒ String
Document ID in structured reference.
18 19 20 |
# File 'lib/glossarist/citation.rb', line 18 def id @id end |
#link ⇒ String
Link to document.
30 31 32 |
# File 'lib/glossarist/citation.rb', line 30 def link @link end |
#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.
36 37 38 |
# File 'lib/glossarist/citation.rb', line 36 def original @original end |
#source ⇒ String
Source in structured reference.
14 15 16 |
# File 'lib/glossarist/citation.rb', line 14 def source @source end |
#text ⇒ String
Unstructured (plain text) reference.
10 11 12 |
# File 'lib/glossarist/citation.rb', line 10 def text @text end |
#version ⇒ String
Document version in structured reference.
22 23 24 |
# File 'lib/glossarist/citation.rb', line 22 def version @version end |
Class Method Details
.from_h(hash) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/glossarist/citation.rb', line 59 def self.from_h(hash) hash = hash.dup ref_val = hash.delete("ref") hash.merge!(Hash === ref_val ? ref_val : {"text" => ref_val}) hash.compact! super(hash) end |
Instance Method Details
#plain? ⇒ Boolean
Whether it is a plain text ref.
40 41 42 |
# File 'lib/glossarist/citation.rb', line 40 def plain? (source && id && version).nil? end |
#ref=(ref) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/glossarist/citation.rb', line 69 def ref=(ref) if ref.is_a?(Hash) @source = ref["source"] @id = ref["id"] @version = ref["version"] else @text = ref end end |
#structured? ⇒ Boolean
Whether it is a structured ref.
46 47 48 |
# File 'lib/glossarist/citation.rb', line 46 def structured? !plain? end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/glossarist/citation.rb', line 50 def to_h { "ref" => ref_to_h, "clause" => clause, "link" => link, "original" => original, }.compact end |