Class: RelatonItu::EditorialGroup
- Inherits:
-
Object
- Object
- RelatonItu::EditorialGroup
- Defined in:
- lib/relaton_itu/editorial_group.rb
Constant Summary collapse
- BUREAUS =
%w[T D R].freeze
Instance Attribute Summary collapse
- #bureau ⇒ String readonly
-
#group ⇒ Object
readonly
Returns the value of attribute group.
- #subgroup ⇒ RelatonItu::ItuGroup, NilClass readonly
- #workgroup ⇒ RelatonItu::ItuGroup, NilClass readonly
Instance Method Summary collapse
-
#initialize(bureau:, group:, subgroup: nil, workgroup: nil) ⇒ EditorialGroup
constructor
A new instance of EditorialGroup.
- #presence? ⇒ true
- #to_asciibib(prefix) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(bureau:, group:, subgroup: nil, workgroup: nil) ⇒ EditorialGroup
Returns a new instance of EditorialGroup.
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 Util.warn "Invalid bureau: `#{bureau}`\nValid bureaus are: `#{BUREAUS.join('`, `')}`" 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
#bureau ⇒ String (readonly)
6 7 8 |
# File 'lib/relaton_itu/editorial_group.rb', line 6 def bureau @bureau end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
9 10 11 |
# File 'lib/relaton_itu/editorial_group.rb', line 9 def group @group end |
#subgroup ⇒ RelatonItu::ItuGroup, NilClass (readonly)
12 13 14 |
# File 'lib/relaton_itu/editorial_group.rb', line 12 def subgroup @subgroup end |
#workgroup ⇒ RelatonItu::ItuGroup, NilClass (readonly)
12 13 14 |
# File 'lib/relaton_itu/editorial_group.rb', line 12 def workgroup @workgroup end |
Instance Method Details
#presence? ⇒ true
29 30 31 |
# File 'lib/relaton_itu/editorial_group.rb', line 29 def presence? true end |
#to_asciibib(prefix) ⇒ 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_hash ⇒ 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
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 |