Class: Iora::Models::Element

Inherits:
Object
  • Object
show all
Extended by:
Associations::HasAttribute, Associations::HasMany, Associations::HasOne
Defined in:
lib/iora/models/element.rb

Overview

Element subclasses represent XML elements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Associations::HasOne

has_one

Methods included from Associations::Helpers

#parse_element, #tag_for

Methods included from Associations::HasMany

has_many

Methods included from Associations::HasAttribute

has_attribute

Constructor Details

#initialize(element) ⇒ Element

Create a new element.

Parameters:

  • element (String, Nokogiri::XML::Document, Nokogiri::XML::NodeSet, Nokogiri::XML::Node)

    the XML element node. If this is a Nokogiri::XML::NodeSet, the first node will be used. If this is a String or a Nokogiri::XML::Document, the root node will be used.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/iora/models/element.rb', line 20

def initialize(element)
  case element
  when String
    @element = Nokogiri::XML::Document.parse(element).root
  when Nokogiri::XML::Document
    @element = element.root
  when Nokogiri::XML::NodeSet
    @element = element.first
  when Nokogiri::XML::Node
    @element = element
  else
    raise ArgumentError, "Unexpected #{element.class}"
  end
end

Instance Attribute Details

#elementNokogiri::XML::Node

Returns the Nokogiri::XML::Nodeobject.

Returns:

  • (Nokogiri::XML::Node)

    the Nokogiri::XML::Nodeobject


37
38
39
# File 'lib/iora/models/element.rb', line 37

def element
  @element
end

Instance Method Details

#to_xmlString Also known as: inspect

Returns the element's XML string.

Returns:

  • (String)

    the element's XML string


41
42
43
# File 'lib/iora/models/element.rb', line 41

def to_xml
  @element.to_xml
end