Class: HtmlParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ HtmlParser

Returns a new instance of HtmlParser.



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

def initialize(html)
  @doc = Nokogiri::HTML.parse(html)
end

Instance Attribute Details

#descriptionsObject

Returns the value of attribute descriptions.



6
7
8
# File 'lib/html_parser.rb', line 6

def descriptions
  @descriptions
end

#docObject

Returns the value of attribute doc.



6
7
8
# File 'lib/html_parser.rb', line 6

def doc
  @doc
end

#metadataObject

Returns the value of attribute metadata.



6
7
8
# File 'lib/html_parser.rb', line 6

def 
  @metadata
end

#summariesObject

Returns the value of attribute summaries.



6
7
8
# File 'lib/html_parser.rb', line 6

def summaries
  @summaries
end

#titlesObject

Returns the value of attribute titles.



6
7
8
# File 'lib/html_parser.rb', line 6

def titles
  @titles
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
# File 'lib/html_parser.rb', line 12

def parse
  @titles = @doc.css('dt > h3')
  @metadata =  @doc.css('ul.entry-metadata > li.entry-type > span')
  @summaries = @doc.css('div.entry-summary > p')
  @descriptions = @doc.css('div.entry-document')
  clean_string
end