Sha256: f587c35fad6bc33354a7c72d2a593268d794bd32442ea830d242fb87d564a18e

Contents?: true

Size: 1.85 KB

Versions: 27

Compression:

Stored size: 1.85 KB

Contents

module RelatonItu
  class ItuGroup
    class Period
      # @return [String] group period start year
      attr_reader :start

      # @return [String, NilClass] group period end year
      attr_reader :finish

      # @params start [String]
      # @params finish [String, NilClass]
      def initialize(start:, finish: nil)
        @start = start
        @finish = finish
      end

      # @param builder [Nokogiri::XML::Builder]
      def to_xml(builder)
        builder.period do
          builder.start start
          builder.end finish if finish
        end
      end

      # @return [Hash]
      def to_hash
        hash = { "start" => start }
        hash["finish"] = finish if finish
        hash
      end
    end

    TYPES = %w[tsag study-group work-group].freeze

    # @return [String]
    attr_reader :name

    # @return [String, NilClass]
    attr_reader :type, :acronym

    # @return [RelatonItu::ItuGroup::Period, NilClass] group period
    attr_reader :period

    # @param type [String, NilClass]
    # @param name [String]
    # @param acronym [String, NilClass]
    # @param period [Hash, RelatonItu::ItuGroup::Period, NilClass]
    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

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.parent[:type] = type if type
      builder.name name
      builder.acronym acronym if acronym
      period&.to_xml builder
    end

    # @return [Hash]
    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
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/relaton-itu-1.2.0/lib/relaton_itu/itu_group.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/relaton-itu-1.2.0/lib/relaton_itu/itu_group.rb
relaton-itu-1.2.0 lib/relaton_itu/itu_group.rb
relaton-itu-1.1.0 lib/relaton_itu/itu_group.rb
relaton-itu-1.0.4 lib/relaton_itu/itu_group.rb
relaton-itu-1.0.2 lib/relaton_itu/itu_group.rb
relaton-itu-1.0.1 lib/relaton_itu/itu_group.rb
relaton-itu-1.0.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.9.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.8.1 lib/relaton_itu/itu_group.rb
relaton-itu-0.8.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.7.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.6.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.5.1 lib/relaton_itu/itu_group.rb
relaton-itu-0.5.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.4.1 lib/relaton_itu/itu_group.rb
relaton-itu-0.4.0 lib/relaton_itu/itu_group.rb
relaton-itu-0.3.11 lib/relaton_itu/itu_group.rb
relaton-itu-0.3.10 lib/relaton_itu/itu_group.rb
relaton-itu-0.3.9 lib/relaton_itu/itu_group.rb