Class: WahlrechtDe::Survey
- Inherits:
-
Object
- Object
- WahlrechtDe::Survey
- Defined in:
- lib/survey.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize ⇒ Survey
constructor
A new instance of Survey.
- #parse(index) ⇒ Object
- #parse_rowdata(row) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Survey
Returns a new instance of Survey.
10 11 12 13 14 |
# File 'lib/survey.rb', line 10 def initialize doc = Nokogiri::HTML(open("http://www.wahlrecht.de/umfragen/index.htm")) @rows = doc.xpath("//table/tbody/tr") @datalines = [] end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
8 9 10 |
# File 'lib/survey.rb', line 8 def rows @rows end |
Instance Method Details
#parse(index) ⇒ Object
16 17 18 19 20 |
# File 'lib/survey.rb', line 16 def parse index row = @rows[index] row_data = parse_rowdata row @datalines.push(Dataline.new(row.at_xpath("th/text()").to_s, row_data)) end |
#parse_rowdata(row) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/survey.rb', line 22 def parse_rowdata row row_data = [] datas = row.xpath("td") datas.each do |data| row_data.push(data.at_xpath("text()").to_s) end row_data end |
#to_s ⇒ Object
31 32 33 34 35 |
# File 'lib/survey.rb', line 31 def to_s @datalines.each do |dataline| puts dataline end end |