Class: Cts::Mpx::Driver::Page

Inherits:
Object
  • Object
show all
Includes:
Creatable, Enumerable
Defined in:
lib/cts/mpx/driver/page.rb

Overview

<Description>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePage

Returns a new instance of Page.



16
17
18
19
# File 'lib/cts/mpx/driver/page.rb', line 16

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

Instance Attribute Details

#entriesArray

Returns array of deserialized entries.

Returns:

  • (Array)

    array of deserialized entries



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cts/mpx/driver/page.rb', line 9

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

#xmlnsHash

Returns active namespace received for this page.

Returns:

  • (Hash)

    active namespace received for this page



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cts/mpx/driver/page.rb', line 9

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

Instance Method Details

#to_mpx_entriesObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/cts/mpx/driver/page.rb', line 21

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

#to_s(indent_depth = nil) ⇒ String

return a json copy of the object, useful for later interpreation

Parameters:

  • indent_depth (Object) (defaults to: nil)

    sets indent depth to 2 if not nil

Returns:

  • (String)

    json serialized copy of the page



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cts/mpx/driver/page.rb', line 35

def to_s(indent_depth = nil)
  indent_depth = 2 if indent_depth

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