upton 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/utils.rb +27 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2M0NjVlMWNlN2ZkNTEwMzIzYmQ2N2MxYjBjZjExZmQ1ZTYyZjAzNw==
4
+ NWMxNTc5MGRjODQzYjNmNWVkODVkNDg1NmM0ODJkMmI1YWU1YmZlYw==
5
5
  data.tar.gz: !binary |-
6
- NTg4NTc3NDQ3OWQ1OGRiY2Y0ZmFkYjI5OWU2NmRkNjVlNDNlYzRkZQ==
6
+ MGI1YTQ1MjM5OGMwZTU2NGVjYWE4OWY5NzY5YjE3OGE4Y2E5ZjdhMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzY5YWNlMTIwNWM5YTNiM2YwMDkwNDNhMTlhNjM2ZTQyMWQ1YjRhMTUwNThm
10
- YThkYzU4ZjI2ZWU0YzA1MjRjMDgxMmEwOGU1MGFlYjMyZDZjYTNjOGU3NDAy
11
- OTQ0Yzc5NTNiNWU0MjE0YTZmYWZkZTQxZjQ1NjliZGEyOGYyZWI=
9
+ NTUwZDkyZDcxMDJiMjBhYzE3NTZjNjQ3NGRiNTdjZjFlOGY3OGI1MTZkZjk3
10
+ ZmQyYzk0YTYzZWI4NzAzMWUyZmNkNmUyZmMxNWI2ZGU2Zjg4NGM2MmY1MmJk
11
+ NWU0MmRjN2EyMjA3MjM1NWMyZTE0YTNjMDc0MDEyZGU3NGM4ZmY=
12
12
  data.tar.gz: !binary |-
13
- Zjg4ODk0ZGZjMDVkZGE5MGEzMTk1Mjg0MzQ1ODllZjUzZjc2MWFjOTU3YzAz
14
- YzE5ZDAyZGZmNDdmZDU3ZWViZTEzNjNhZGNmMGZmMDgwY2YxYTgwZjkxNzFj
15
- NTMwODU4ODg2Nzg2NGYzOGU2NmJhNDBmNmI1OWQwZDVkN2UzZmM=
13
+ ODNjYzc3ODEzYzM5ZjA4OWI3NDA3YmRkODYwMWI0NTk4OTY1NzI3ZGM2OWMx
14
+ ZmUwZDk3ZTA0MThmNDFkOTM3NjRlMTA0MTM5MTk5ODlmYzc3MzFkM2IyZmY0
15
+ YWFmNmEzNzRjOGFiZDY2Njc5ZDEzMzQzMjgwZTZhYjIyYmYxMzQ=
data/lib/utils.rb ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+
3
+ module Upton
4
+ module Utils
5
+ #instance_html, instance_url, index
6
+ def self.table(table_selector, selector_method=:xpath)
7
+ require 'csv'
8
+ return Proc.new do |instance_html|
9
+ html = ::Nokogiri::HTML(instance_html)
10
+ output = []
11
+ headers = html.send(selector_method, table_selector).css("th").map &:text
12
+ output << headers
13
+
14
+ table = html.send(selector_method, table_selector).css("tr").each{|tr| output << tr.css("td").map(&:text) }
15
+ output
16
+ end
17
+ end
18
+
19
+ def self.list(list_selector, selector_method=:xpath)
20
+ require 'csv'
21
+ return Proc.new do |instance_html|
22
+ html = ::Nokogiri::HTML(instance_html)
23
+ html.send(selector_method, list_selector).map{|list_element| list_element.text }
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy B. Merrill
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - lib/upton.rb
105
+ - lib/utils.rb
105
106
  - test/data/discussion.html
106
107
  - test/data/easttimor.html
107
108
  - test/data/propublica.html