Class: WahlrechtDe::Survey

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSurvey

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

#rowsObject (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_sObject



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

def to_s
	@datalines.each do |dataline|
		puts dataline
	end
end