Sha256: 57f059cdda384a0c2b86715e972184eb6735e5bb70046f17c1be70f3a60c51d5

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Metacrunch
  class SNR
    class Section

      attr_reader :name

      def initialize(name)
        raise ArgumentError, "required Section#name not given" if name.nil?

        @name   = name
        @fields = []
      end

      # ------------------------------------------------------------------------------
      # Common API
      # ------------------------------------------------------------------------------

      #
      # Adds a field
      #
      def add(field_name, value)
        add_field(Field.new(field_name, value))
      end

      # ------------------------------------------------------------------------------
      # Fields
      # ------------------------------------------------------------------------------

      #
      # Return all fields.
      #
      # @return [Array<Metacrunch::SNR::Section::Field>]
      #
      def fields
        @fields
      end

      #
      # Adds a new field to this section.
      #
      # @param [Metacrunch::SNR::Section::Field] field
      # @return [Metacrunch::SNR::Section::Field]
      #
      def add_field(field)
        @fields << field
        field
      end

      # ------------------------------------------------------------------------------
      # Serialization
      # ------------------------------------------------------------------------------

      def to_xml(builder)
        builder.tag!(self.name) do
          @fields.each do |_field|
            _field.to_xml(builder)
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metacrunch-2.1.1 lib/metacrunch/snr/section.rb
metacrunch-2.1.0 lib/metacrunch/snr/section.rb