Class: Kiosk::Claim::NodeClaim
- Inherits:
-
Object
- Object
- Kiosk::Claim::NodeClaim
- Defined in:
- lib/kiosk/claim/node_claim.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Instance Method Summary collapse
-
#initialize(model, options = {}, &parser) ⇒ NodeClaim
constructor
A new instance of NodeClaim.
-
#stake!(document) ⇒ Object
Stakes the claim over the given content document and yields the provided block for each match.
Constructor Details
#initialize(model, options = {}, &parser) ⇒ NodeClaim
Returns a new instance of NodeClaim.
6 7 8 9 10 11 12 13 |
# File 'lib/kiosk/claim/node_claim.rb', line 6 def initialize(model, = {}, &parser) raise ArgumentError.new('no selector given') unless [:selector] raise ArgumentError.new('no block provided') unless block_given? @model = model @selector = [:selector] @parser = parser end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/kiosk/claim/node_claim.rb', line 4 def model @model end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
4 5 6 |
# File 'lib/kiosk/claim/node_claim.rb', line 4 def parser @parser end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
4 5 6 |
# File 'lib/kiosk/claim/node_claim.rb', line 4 def selector @selector end |
Instance Method Details
#stake!(document) ⇒ Object
Stakes the claim over the given content document and yields the provided block for each match. The block is passed each node, which has been extended with implementation in ClaimedNode
.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kiosk/claim/node_claim.rb', line 19 def stake!(document) select_from(document).each do |node| unless node.is_a?(ClaimedNode) node.extend(ProspectiveNode) unless node.is_a?(ProspectiveNode) # If the parser finds anything in the selected node, stake the claim if attributes = parser.call(node) node.extend(ClaimedNode) node.resource = @model.new(attributes) yield node if block_given? end end end end |