Class: Ahora::Representation

Inherits:
Nibbler
  • Object
show all
Extended by:
Definition
Defined in:
lib/ahora/representation.rb

Direct Known Subclasses

Response

Defined Under Namespace

Modules: Definition

Constant Summary collapse

STRING_PARSER =
lambda { |node| node.content             if present.call(node.content) }
INTEGER_PARSER =
lambda { |node| Integer(node.content)    if present.call(node.content) }
FLOAT_PARSER =
lambda { |node| Float(node.content)      if present.call(node.content) }
DATE_PARSER =
lambda { |node| Date.parse(node.content) if present.call(node.content) }
TIME_PARSER =
lambda { |node| Time.parse(node.content) if present.call(node.content) }
BOOL_PARSER =
lambda { |node| node.content.to_s.downcase == 'true' }

Instance Method Summary collapse

Methods included from Definition

attribute, attribute_selector, boolean, date, element, float, integer, string, time

Constructor Details

#initialize(doc_or_atts = {}) ⇒ Representation

Returns a new instance of Representation.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ahora/representation.rb', line 82

def initialize(doc_or_atts = {})
  if doc_or_atts.is_a? Hash
    super("")
    doc_or_atts.each do |key, val|
      send("#{key}=", val)
    end
  else
    doc = doc_or_atts
    doc = XmlParser.parse(doc) unless doc.respond_to?(:search)
    if doc.node_type == Nokogiri::XML::Node::DOCUMENT_NODE
      # immediately scope to root element
      doc = doc.at('/*')
    end
    super(doc)
  end
end