Class: Cut::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/cut/mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Mapping

Returns a new instance of Mapping.



6
7
8
9
10
# File 'lib/cut/mapping.rb', line 6

def initialize(name, options = {})
  @name      = name
  @selector  = options[:to]
  @operation = options[:operation]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/cut/mapping.rb', line 4

def name
  @name
end

Instance Method Details

#operationObject



16
17
18
# File 'lib/cut/mapping.rb', line 16

def operation
  @operation ||= Proc.new {|value| value }
end

#selectorObject



12
13
14
# File 'lib/cut/mapping.rb', line 12

def selector
  @selector ||= ".#{name}"
end

#value_from_node(node) ⇒ Object



20
21
22
# File 'lib/cut/mapping.rb', line 20

def value_from_node(node)
  operation.call( node.at_css(selector).value.to_s )
end