Class: HappyMapper::Attribute

Inherits:
Item
  • Object
show all
Defined in:
lib/happymapper/attribute.rb

Instance Attribute Summary collapse

Attributes inherited from Item

#name, #namespace, #options, #tag, #type

Instance Method Summary collapse

Methods inherited from Item

#constant, #from_xml_node, #method_name, #typecast, #xpath

Constructor Details

#initialize(name, type, options = {}) ⇒ Attribute

Additional options:

:default => Object The default value for this

See Also:


10
11
12
13
# File 'lib/happymapper/attribute.rb', line 10

def initialize(name, type, options = {})
  super
  self.default = options[:default]
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default


5
6
7
# File 'lib/happymapper/attribute.rb', line 5

def default
  @default
end

Instance Method Details

#find(node, _namespace, xpath_options) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/happymapper/attribute.rb', line 15

def find(node, _namespace, xpath_options)
  if options[:xpath]
    yield(node.xpath(options[:xpath], xpath_options))
  else
    yield(node.attributes[tag])
  end
end