Class: RelatonBib::WorkGroup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, identifier: nil, prefix: nil, number: nil, type: nil) ⇒ WorkGroup

Returns a new instance of WorkGroup.

Parameters:

  • name (String)
  • identifier (String, nil) (defaults to: nil)
  • prefix (String, nil) (defaults to: nil)
  • number (Integer, nil) (defaults to: nil)
  • type (String, nil) (defaults to: nil)


17
18
19
20
21
22
23
# File 'lib/relaton_bib/workgroup.rb', line 17

def initialize(name:, identifier: nil, prefix: nil, number: nil, type: nil)
  @identifier = identifier
  @prefix = prefix
  @name = name
  @number = number
  @type = type
end

Instance Attribute Details

#identifierString? (readonly)

Returns:

  • (String, nil)


10
11
12
# File 'lib/relaton_bib/workgroup.rb', line 10

def identifier
  @identifier
end

#nameString (readonly)

Returns:

  • (String)


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

def name
  @name
end

#numberInteger? (readonly)

Returns:

  • (Integer, nil)


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

def number
  @number
end

#prefixString? (readonly)

Returns:

  • (String, nil)


10
11
12
# File 'lib/relaton_bib/workgroup.rb', line 10

def prefix
  @prefix
end

#typeString? (readonly)

Returns:

  • (String, nil)


10
11
12
# File 'lib/relaton_bib/workgroup.rb', line 10

def type
  @type
end

Instance Method Details

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

Parameters:

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

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
# File 'lib/relaton_bib/workgroup.rb', line 47

def to_asciibib(prfx = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity
  pref = prfx.empty? ? prfx : "#{prfx}."
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}name:: #{name}\n"
  out += "#{pref}number:: #{number}\n" if number
  out += "#{pref}type:: #{type}\n" if type
  out += "#{pref}identifier:: #{identifier}\n" if identifier
  out += "#{pref}prefix:: #{prefix}\n" if prefix
  out
end

#to_hashHash

Returns:

  • (Hash)


35
36
37
38
39
40
41
42
# File 'lib/relaton_bib/workgroup.rb', line 35

def to_hash
  hash = { "name" => name }
  hash["number"] = number if number
  hash["type"] = type if type
  hash["identifier"] = identifier if identifier
  hash["prefix"] = prefix if prefix
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


26
27
28
29
30
31
32
# File 'lib/relaton_bib/workgroup.rb', line 26

def to_xml(builder) # rubocop:disable Metrics/AbcSize
  builder.text name
  builder.parent[:number] = number if number
  builder.parent[:type] = type if type
  builder.parent[:identifier] = identifier if identifier
  builder.parent[:prefix] = prefix if prefix
end