Class: WahlrechtDe::Dataline

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

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Dataline

Returns a new instance of Dataline.



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

def initialize row
	@name = row.at_xpath("th/text()").to_s
	@prognosis = parse_rowdata row
end

Instance Method Details

#cut_extremesObject



29
30
31
32
33
34
# File 'lib/dataline.rb', line 29

def cut_extremes
	sorted_prognosis = @prognosis.sort
	sorted_prognosis.pop
	sorted_prognosis.shift
	sorted_prognosis
end

#parse_rowdata(row) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dataline.rb', line 11

def parse_rowdata row
	row_data = []
	datas = row.xpath("td")
	datas.pop
	datas.each do |data|
		string_data = data.at_xpath("text()").to_s
		unless (string_data == "" or string_data == "–")
			row_data.push Datapoint.new string_data
		end
	end
	row_data
end

#prognosis_rangeObject



24
25
26
27
# File 'lib/dataline.rb', line 24

def prognosis_range
	cut_and_sorted_prognosis = cut_extremes
	[cut_and_sorted_prognosis[0], cut_and_sorted_prognosis.last]
end

#to_sObject



36
37
38
39
40
41
42
43
# File 'lib/dataline.rb', line 36

def to_s
	range = prognosis_range
	if range[0] == range[1]
		"#{@name}: #{range[0]}%"
	else
	  "#{@name}: #{range[0]}% bis #{range[1]}%"
	end
end