Class: Nokogireader::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/nokogireader/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefinition



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_textObject

Returns the value of attribute accept_text.



4
5
6
# File 'lib/nokogireader/definition.rb', line 4

def accept_text
  @accept_text
end

#after_callbackObject

Returns the value of attribute after_callback.



4
5
6
# File 'lib/nokogireader/definition.rb', line 4

def after_callback
  @after_callback
end

#childrenObject (readonly)

Returns the value of attribute children.



3
4
5
# File 'lib/nokogireader/definition.rb', line 3

def children
  @children
end

#dont_store_dataObject

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

#multipleObject

Returns the value of attribute multiple.



4
5
6
# File 'lib/nokogireader/definition.rb', line 4

def multiple
  @multiple
end

#read_attributesObject

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