Sha256: 6fd22dbb72983422935284ac4a43ae19f1fab2fc2a7f2a78fda5f51ee41f3079

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Cts
  module Mpx
    module Driver
      # <Description>
      # @attribute entries
      #   @return [Array] array of deserialized entries
      # @attribute xmlns
      #   @return [Hash] active namespace received for this page
      class Page
        include Creatable
        include Enumerable

        attribute name: 'entries', kind_of: Array
        attribute name: 'xmlns', kind_of: Hash

        def initialize
          @entries = []
          @xmlns = {}
        end

        def to_mpx_entries
          c = @entries.map do |e|
            new_entry = Entry.create(fields: Fields.create_from_data(data: e, xmlns: xmlns))
            new_entry.id = new_entry.fields['id']
            new_entry
          end

          e = Entries.create collection: c
          e
        end

        # return a json copy of the object, useful for later interpreation
        # @param [Object] indent_depth sets indent depth to 2 if not nil
        # @return [String] json serialized copy of the page
        def to_s(indent_depth = nil)
          indent_depth = 2 if indent_depth

          Oj.dump(
            {
              "xmlns"   => xmlns,
              "entries" => entries
            },
            indent: indent_depth
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cts-mpx-1.0.3 lib/cts/mpx/driver/page.rb