Class: Slasher

Inherits:
Object
  • Object
show all
Defined in:
lib/slasher.rb,
lib/slasher/dom.rb,
lib/slasher/content.rb

Defined Under Namespace

Classes: Content, DOM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Slasher

Returns a new instance of Slasher.



7
8
9
10
# File 'lib/slasher.rb', line 7

def initialize(html)
  @dom      = Slasher::DOM.new(html)
  @content  = Slasher::Content.new
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/slasher.rb', line 5

def content
  @content
end

#domObject

Returns the value of attribute dom.



5
6
7
# File 'lib/slasher.rb', line 5

def dom
  @dom
end

Instance Method Details

#recursive_slash(doc) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/slasher.rb', line 12

def recursive_slash(doc)
  content.push_content(dom.get_texts(doc))

  doc.children.each do |child|
    if child.send(:>, "p").count > 0
      content.push_content dom.get_paragraphs_content(child)
    end

    if child.children.count > 0
      recursive_slash(child)
    else
      content.push_content(child.text) if child.text != '' && !child.text.nil?
    end
  end
end

#reset(html) ⇒ Object



28
29
30
31
# File 'lib/slasher.rb', line 28

def reset(html)
  @dom     = Slasher::DOM.new(html)
  @content = Slasher::Content.new
end

#slashObject



33
34
35
36
37
38
# File 'lib/slasher.rb', line 33

def slash
  dom.remove_elements
  dom.strip_elements
  recursive_slash(dom.document)
  content.get_longest_length[:content]
end