tributa 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/tributa/html_to_tributa_table_transformer.rb +26 -24
- data/lib/tributa/table/row.rb +12 -10
- data/lib/tributa/table.rb +12 -10
- data/lib/tributa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 168648ce147b91dcfd81733a7a73faffce8ffc628591fd4dcf414595488c4546
|
4
|
+
data.tar.gz: f0c267805bbfff7fa30c2a7c90e53c6c1576fc1b322114821339a233d8d14bd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f6c9d09ef8fb66e28ff54a02fc19a00fb961f810dd106eea4fffa11b714869a0381217fb643e5862e95410772c312c093d771b42e2acdef669258479757d0b4
|
7
|
+
data.tar.gz: 901e53ea53069eb72321abc743f7ef6d195079e7e3be82e08851663af62df1face08c2844684f617adec2bba0f13f1794b31b6a1181ed3aa44f605c767f9a4eb
|
data/Gemfile.lock
CHANGED
@@ -2,37 +2,39 @@ require 'nokogiri'
|
|
2
2
|
require_relative 'table'
|
3
3
|
require_relative 'table/row'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Tributa
|
6
|
+
class HtmlToTributaTableTransformer
|
7
|
+
attr_reader :html
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(html)
|
10
|
+
@html = html
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def to_tributa_table
|
14
|
+
Tributa::Table.new(rows)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
+
private
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def nhtml
|
20
|
+
@nhtml ||= Nokogiri::HTML(sanitize_html)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def rows
|
24
|
+
nokogiri_rows.map(&method(:to_tributa_table_row))
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def nokogiri_rows
|
28
|
+
nhtml.xpath('//table//tr')[2..]
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def sanitize_html
|
32
|
+
@sanitize_html ||= html[/<table class=.rahmen. width=.950.>(.*)<\/table><BR><BR>/i].gsub(/<br><br>$/i, '')
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def to_tributa_table_row(nokogiri_row)
|
36
|
+
values = nokogiri_row.xpath('td').map(&:text)
|
37
|
+
Tributa::Table::Row.new(values)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
data/lib/tributa/table/row.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Tributa
|
2
|
+
class Table::Row
|
3
|
+
attr_reader :canton, :year, :community, :canton_rate, :community_rate, :reformed_rate, :catholic_rate
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def initialize(columns = [])
|
6
|
+
@canton,
|
7
|
+
@year,
|
8
|
+
@community,
|
9
|
+
@canton_rate,
|
10
|
+
@community_rate,
|
11
|
+
@reformed_rate,
|
12
|
+
@catholic_rate = columns
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/tributa/table.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Tributa
|
2
|
+
class Table
|
3
|
+
attr_reader :rows
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(rows)
|
6
|
+
@rows = rows
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def find_all_by(canton:, community:, year:)
|
10
|
+
rows.find_all do |row|
|
11
|
+
row.canton == canton &&
|
12
|
+
row.community == community &&
|
13
|
+
row.year == year.to_s
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
data/lib/tributa/version.rb
CHANGED