Class: RelatonBib::Classification

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/classification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, value:) ⇒ Classification

Returns a new instance of Classification.

Parameters:

  • type (String, NilClass) (defaults to: nil)
  • value (String)


11
12
13
14
# File 'lib/relaton_bib/classification.rb', line 11

def initialize(type: nil, value:)
  @type  = type
  @value = value
end

Instance Attribute Details

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


4
5
6
# File 'lib/relaton_bib/classification.rb', line 4

def type
  @type
end

#valueString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/relaton_bib/classification.rb', line 7

def value
  @value
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ String

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

    number of classifications

Returns:

  • (String)


32
33
34
35
36
37
38
# File 'lib/relaton_bib/classification.rb', line 32

def to_asciibib(prefix = "", count = 1)
  pref = prefix.empty? ? "classification" : prefix + ".classification"
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}.type:: #{type}\n" if type
  out += "#{pref}.value:: #{value}\n"
  out
end

#to_hashHash

Returns:

  • (Hash)


23
24
25
26
27
# File 'lib/relaton_bib/classification.rb', line 23

def to_hash
  hash = { "value" => value }
  hash["type"] = type if type
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


17
18
19
20
# File 'lib/relaton_bib/classification.rb', line 17

def to_xml(builder)
  xml = builder.classification value
  xml[:type] = type if type
end