Class: RelatonIsoBib::EditorialGroup

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_iso_bib/editorial_group.rb

Overview

ISO project group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(technical_committee:, **args) ⇒ EditorialGroup

Returns a new instance of EditorialGroup.

Parameters:

  • technical_committee (Array<Hash, RelatonIsoBib::IsoSubgroup>)
  • subcommittee (Array<Hash, RelatonIsoBib::IsoSubgroup>)
  • workgroup (Array<Hash, RelatonIsoBib::IsoSubgroup>)
  • secretariat (String, NilClass)

Options Hash (technical_committee:):

  • :name (String)
  • :type (String)
  • :number (Integer)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/relaton_iso_bib/editorial_group.rb', line 36

def initialize(technical_committee:, **args) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
  @technical_committee = technical_committee.map do |tc|
    tc.is_a?(Hash) ? RelatonBib::WorkGroup.new(**tc) : tc
  end
  @subcommittee = args.fetch(:subcommittee, []).map do |sc|
    sc.is_a?(Hash) ? RelatonBib::WorkGroup.new(**sc) : sc
  end
  @workgroup = args.fetch(:workgroup, []).map do |wg|
    wg.is_a?(Hash) ? RelatonBib::WorkGroup.new(**wg) : wg
  end
  @secretariat = args[:secretariat]
end

Instance Attribute Details

#secretariatString, NilClass (readonly)

Returns:

  • (String, NilClass)


18
19
20
# File 'lib/relaton_iso_bib/editorial_group.rb', line 18

def secretariat
  @secretariat
end

#subcommitteeArray<RelatonIsoBib::IsoSubgroup> (readonly)

Returns:

  • (Array<RelatonIsoBib::IsoSubgroup>)


12
13
14
# File 'lib/relaton_iso_bib/editorial_group.rb', line 12

def subcommittee
  @subcommittee
end

#technical_committeeArray<RelatonIsoBib::IsoSubgroup> (readonly)

Returns:

  • (Array<RelatonIsoBib::IsoSubgroup>)


9
10
11
# File 'lib/relaton_iso_bib/editorial_group.rb', line 9

def technical_committee
  @technical_committee
end

#workgroupArray<RelatonIsoBib::IsoSubgroup> (readonly)

Returns:

  • (Array<RelatonIsoBib::IsoSubgroup>)


15
16
17
# File 'lib/relaton_iso_bib/editorial_group.rb', line 15

def workgroup
  @workgroup
end

Instance Method Details

#presence?true

Returns:

  • (true)


50
51
52
# File 'lib/relaton_iso_bib/editorial_group.rb', line 50

def presence?
  true
end

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/relaton_iso_bib/editorial_group.rb', line 88

def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  pref = prefix.empty? ? prefix : "#{prefix}."
  pref += "editorialgroup"
  out = ""
  technical_committee.each do |tc|
    out += tc.to_asciibib "#{pref}.technical_committee",
                          technical_committee.size
  end
  subcommittee.each do |sc|
    out += sc.to_asciibib "#{pref}.subcommittee", subcommittee.size
  end
  workgroup.each do |wg|
    out += wg.to_asciibib "#{pref}.workgroup", workgroup.size
  end
  out += "#{pref}.secretariat:: #{secretariat}\n" if secretariat
  out
end

#to_hashHash

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
83
84
# File 'lib/relaton_iso_bib/editorial_group.rb', line 74

def to_hash # rubocop:disable Metrics/AbcSize
  hash = {
    "technical_committee" => single_element_array(technical_committee),
  }
  if subcommittee&.any?
    hash["subcommittee"] = single_element_array(subcommittee)
  end
  hash["workgroup"] = single_element_array(workgroup) if workgroup&.any?
  hash["secretariat"] = secretariat if secretariat
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/relaton_iso_bib/editorial_group.rb', line 55

def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize, Metrics/MethodLength
  return unless technical_committee || subcommittee || workgroup ||
    secretariat

  builder.editorialgroup do
    technical_committee.each do |tc|
      builder.send("technical-committee") { tc.to_xml builder }
    end
    subcommittee.each do |sc|
      builder.subcommittee { sc.to_xml builder }
    end
    workgroup.each do |wg|
      builder.workgroup { wg.to_xml builder }
    end
    builder.secretariat secretariat if secretariat
  end
end