Class: Shale::Adapter::Ox::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/adapter/ox/node.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper around Ox::Element API

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object with Ox element

Parameters:

  • node (::Ox::Element)

    Ox element



15
16
17
# File 'lib/shale/adapter/ox/node.rb', line 15

def initialize(node)
  @node = node
end

Instance Method Details

#attributesHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return all attributes associated with the node

Returns:

  • (Hash)


52
53
54
# File 'lib/shale/adapter/ox/node.rb', line 52

def attributes
  @node.attributes
end

#childrenArray<Shale::Adapter::Ox::Node>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return node’s element children

Returns:



70
71
72
73
74
75
# File 'lib/shale/adapter/ox/node.rb', line 70

def children
  @node
    .nodes
    .filter { |e| e.is_a?(::Ox::Element) }
    .map { |e| self.class.new(e) }
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return name of the node in the format of prefix:name when the node is namespaced or just name when it’s not

Examples:

without namespace

node.name # => Bar

with namespace

node.name # => foo:Bar

Returns:

  • (String)


43
44
45
# File 'lib/shale/adapter/ox/node.rb', line 43

def name
  @node.name
end

#namespacesHash<String, String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return namespaces defined on document (Not supported by Ox)

Examples:

node.namespaces # => {}

Returns:

  • (Hash<String, String>)


27
28
29
# File 'lib/shale/adapter/ox/node.rb', line 27

def namespaces
  {}
end

#parentnil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return node’s parent (Not supported by OX)

Returns:

  • (nil)


61
62
63
# File 'lib/shale/adapter/ox/node.rb', line 61

def parent
  # :noop:
end

#textString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return first text child of a node

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/shale/adapter/ox/node.rb', line 82

def text
  texts = @node.nodes.map do |e|
    case e
    when ::Ox::CData
      e.value
    when ::String
      e
    end
  end

  texts.compact.first
end