Class: Glossarist::Citation

Inherits:
Model
  • Object
show all
Defined in:
lib/glossarist/citation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize, new, #set_attribute

Constructor Details

This class inherits a constructor from Glossarist::Model

Instance Attribute Details

#clauseString

Referred clause of the document.

Returns:

  • (String)


26
27
28
# File 'lib/glossarist/citation.rb', line 26

def clause
  @clause
end

#idString

Document ID in structured reference.

Returns:

  • (String)


18
19
20
# File 'lib/glossarist/citation.rb', line 18

def id
  @id
end

Link to document.

Returns:

  • (String)


30
31
32
# File 'lib/glossarist/citation.rb', line 30

def link
  @link
end

#originalString

Note:

This attribute is likely to be removed or reworked in future. It is arguably not relevant to Glossarist itself.

Original ref text before parsing.

Returns:

  • (String)


36
37
38
# File 'lib/glossarist/citation.rb', line 36

def original
  @original
end

#sourceString

Source in structured reference.

Returns:

  • (String)


14
15
16
# File 'lib/glossarist/citation.rb', line 14

def source
  @source
end

#textString

Unstructured (plain text) reference.

Returns:

  • (String)


10
11
12
# File 'lib/glossarist/citation.rb', line 10

def text
  @text
end

#versionString

Document version in structured reference.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


46
47
48
# File 'lib/glossarist/citation.rb', line 46

def structured?
  !plain?
end

#to_hObject



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