Class: RelatonItu::EditorialGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_itu/editorial_group.rb

Constant Summary collapse

BUREAUS =
%w[T D R].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bureau:, group:, subgroup: nil, workgroup: nil) ⇒ EditorialGroup

Returns a new instance of EditorialGroup.

Parameters:


18
19
20
21
22
23
24
25
26
# File 'lib/relaton_itu/editorial_group.rb', line 18

def initialize(bureau:, group:, subgroup: nil, workgroup: nil)
  unless BUREAUS.include? bureau
    warn "[relaton-itu] WARNING: invalid bureau: #{bureau}"
  end
  @bureau = bureau
  @group = group.is_a?(Hash) ? ItuGroup.new(**group) : group
  @subgroup = subgroup.is_a?(Hash) ? ItuGroup.new(subgroup) : subgroup
  @workgroup = workgroup.is_a?(Hash) ? ItuGroup.new(workgroup) : workgroup
end

Instance Attribute Details

#bureauString (readonly)

Returns:

  • (String)

6
7
8
# File 'lib/relaton_itu/editorial_group.rb', line 6

def bureau
  @bureau
end

#groupObject (readonly)

Returns the value of attribute group


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

def group
  @group
end

#subgroupRelatonItu::ItuGroup, NilClass (readonly)

Returns:


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

def subgroup
  @subgroup
end

#workgroupRelatonItu::ItuGroup, NilClass (readonly)

Returns:


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

def workgroup
  @workgroup
end

Instance Method Details

#presence?true

Returns:

  • (true)

29
30
31
# File 'lib/relaton_itu/editorial_group.rb', line 29

def presence?
  true
end

#to_asciibib(prefix) ⇒ String

Parameters:

  • prefix (String)

Returns:

  • (String)

54
55
56
57
58
59
60
61
62
# File 'lib/relaton_itu/editorial_group.rb', line 54

def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize
  pref = prefix.empty? ? prefix : prefix + "."
  pref += "editorialgroup"
  out = "#{pref}.bureau:: #{bureau}\n"
  out += group.to_asciibib "#{pref}.group" if group
  out += subgroup.to_asciibib "#{pref}.subgroup" if subgroup
  out += workgroup.to_asciibib "#{pref}.workgroup" if workgroup
  out
end

#to_hashHash

Returns:

  • (Hash)

44
45
46
47
48
49
50
# File 'lib/relaton_itu/editorial_group.rb', line 44

def to_hash
  hash = { "bureau" => bureau }
  hash["group"] = group.to_hash if group
  hash["subgroup"] = subgroup.to_hash if subgroup
  hash["workgroup"] = workgroup.to_hash if workgroup
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)

34
35
36
37
38
39
40
41
# File 'lib/relaton_itu/editorial_group.rb', line 34

def to_xml(builder) # rubocop:disable Metrics/AbcSize
  builder.editorialgroup do
    builder.bureau bureau
    builder.group { |b| group.to_xml b } if group
    builder.subgroup { |b| group.to_xml b } if subgroup
    builder.workgroup { |b| group.to_xml b } if workgroup
  end
end