Class: RelatonItu::ItuGroup
- Inherits:
-
Object
- Object
- RelatonItu::ItuGroup
- Defined in:
- lib/relaton_itu/itu_group.rb
Defined Under Namespace
Classes: Period
Constant Summary collapse
- TYPES =
%w[tsag study-group work-group].freeze
Instance Attribute Summary collapse
- #acronym ⇒ String, NilClass readonly
- #name ⇒ String readonly
-
#period ⇒ RelatonItu::ItuGroup::Period, NilClass
readonly
Group period.
- #type ⇒ String, NilClass readonly
Instance Method Summary collapse
-
#initialize(type: nil, name:, acronym: nil, period: nil) ⇒ ItuGroup
constructor
A new instance of ItuGroup.
- #to_asciibib(prefix) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(type: nil, name:, acronym: nil, period: nil) ⇒ ItuGroup
Returns a new instance of ItuGroup.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/relaton_itu/itu_group.rb', line 58 def initialize(type: nil, name:, acronym: nil, period: nil) if type && !TYPES.include?(type) raise ArgumentError, "invalid type: #{type}" end @type = type @name = name @acronym = acronym @period = period.is_a?(Hash) ? Period.new(**period) : period end |
Instance Attribute Details
#acronym ⇒ String, NilClass (readonly)
49 50 51 |
# File 'lib/relaton_itu/itu_group.rb', line 49 def acronym @acronym end |
#name ⇒ String (readonly)
46 47 48 |
# File 'lib/relaton_itu/itu_group.rb', line 46 def name @name end |
#period ⇒ RelatonItu::ItuGroup::Period, NilClass (readonly)
Returns group period.
52 53 54 |
# File 'lib/relaton_itu/itu_group.rb', line 52 def period @period end |
#type ⇒ String, NilClass (readonly)
49 50 51 |
# File 'lib/relaton_itu/itu_group.rb', line 49 def type @type end |
Instance Method Details
#to_asciibib(prefix) ⇒ String
88 89 90 91 92 93 94 95 |
# File 'lib/relaton_itu/itu_group.rb', line 88 def to_asciibib(prefix) pref = prefix.empty? ? prefix : prefix + "." out = "#{pref}name:: #{name}\n" out += "#{pref}type:: #{type}\n" if type out += "#{pref}acronym:: #{acronym}\n" if acronym out += period.to_asciibib prefix if period out end |
#to_hash ⇒ Hash
78 79 80 81 82 83 84 |
# File 'lib/relaton_itu/itu_group.rb', line 78 def to_hash hash = { "name" => name } hash["type"] = type if type hash["acronym"] = acronym if acronym hash["period"] = period.to_hash if period hash end |
#to_xml(builder) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/relaton_itu/itu_group.rb', line 70 def to_xml(builder) builder.parent[:type] = type if type builder.name name builder.acronym acronym if acronym period&.to_xml builder end |