Class: Cut::Mapping
- Inherits:
-
Object
- Object
- Cut::Mapping
- Defined in:
- lib/cut/mapping.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Mapping
constructor
A new instance of Mapping.
- #operation ⇒ Object
- #selector ⇒ Object
- #value_from_node(node) ⇒ Object
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, = {}) @name = name @selector = [:to] @operation = [:operation] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/cut/mapping.rb', line 4 def name @name end |
Instance Method Details
#operation ⇒ Object
16 17 18 |
# File 'lib/cut/mapping.rb', line 16 def operation @operation ||= Proc.new {|value| value } end |
#selector ⇒ Object
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 |