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
27
28
29
# 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
      p_content = dom.get_paragraphs_content(child)
      content.push_content(p_content)
    end

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

#slashObject



31
32
33
34
35
36
# File 'lib/slasher.rb', line 31

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