Class: Nokogireader::Definition
- Inherits:
-
Object
- Object
- Nokogireader::Definition
- Defined in:
- lib/nokogireader/definition.rb
Instance Attribute Summary collapse
-
#accept_text ⇒ Object
Returns the value of attribute accept_text.
-
#after_callback ⇒ Object
Returns the value of attribute after_callback.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#dont_store_data ⇒ Object
Returns the value of attribute dont_store_data.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
-
#read_attributes ⇒ Object
Returns the value of attribute read_attributes.
Instance Method Summary collapse
- #accept?(node) ⇒ Boolean
- #configure(&block) ⇒ Object
-
#initialize ⇒ Definition
constructor
A new instance of Definition.
- #multiple? ⇒ Boolean
- #on_traversed(reader, data) ⇒ Object
Constructor Details
#initialize ⇒ Definition
8 9 10 11 12 13 14 15 |
# File 'lib/nokogireader/definition.rb', line 8 def initialize @read_attributes = [] @after_callback = nil @children = {} @accept_text = false @multiple = false @dont_store_data = false end |
Instance Attribute Details
#accept_text ⇒ Object
Returns the value of attribute accept_text.
4 5 6 |
# File 'lib/nokogireader/definition.rb', line 4 def accept_text @accept_text end |
#after_callback ⇒ Object
Returns the value of attribute after_callback.
4 5 6 |
# File 'lib/nokogireader/definition.rb', line 4 def after_callback @after_callback end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/nokogireader/definition.rb', line 3 def children @children end |
#dont_store_data ⇒ Object
Returns the value of attribute dont_store_data.
4 5 6 |
# File 'lib/nokogireader/definition.rb', line 4 def dont_store_data @dont_store_data end |
#multiple ⇒ Object
Returns the value of attribute multiple.
4 5 6 |
# File 'lib/nokogireader/definition.rb', line 4 def multiple @multiple end |
#read_attributes ⇒ Object
Returns the value of attribute read_attributes.
4 5 6 |
# File 'lib/nokogireader/definition.rb', line 4 def read_attributes @read_attributes end |
Instance Method Details
#accept?(node) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/nokogireader/definition.rb', line 23 def accept?(node) if node.node_type == 1 @children.key?(node.name) elsif node.node_type == 3 @accept_text else false end end |
#configure(&block) ⇒ Object
17 18 19 20 21 |
# File 'lib/nokogireader/definition.rb', line 17 def configure(&block) return self unless block_given? DSL.new(self).instance_eval(&block) self end |
#multiple? ⇒ Boolean
33 34 35 |
# File 'lib/nokogireader/definition.rb', line 33 def multiple? @multiple end |
#on_traversed(reader, data) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/nokogireader/definition.rb', line 37 def on_traversed(reader, data) return unless @after_callback if @after_callback.is_a?(Symbol) reader.send(@after_callback, data) else @after_callback.call(reader, data) end end |