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, o = {}) ⇒ Attribute

Additional options:

:default => Object The default value for this

See Also:



8
9
10
11
# File 'lib/happymapper/attribute.rb', line 8

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

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



3
4
5
# File 'lib/happymapper/attribute.rb', line 3

def default
  @default
end

Instance Method Details

#find(node, _namespace, xpath_options) ⇒ Object



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

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