ncua 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e329a8d091a46b2798649cc3ddd24d42163fed3b
4
- data.tar.gz: 8842978e48032d39ef122a5cee6f99edcd70ff2e
3
+ metadata.gz: d80b3ab492107fa4574336a527522217465ac829
4
+ data.tar.gz: 89b3e21b98a1feaa85d3555d4fe7a3a7b01535dc
5
5
  SHA512:
6
- metadata.gz: a035575691a5c83843d75548f8053d23761ae5b9c28f6cb0fddb34148191dcf401cf09f70d55c26777cb8c523414585fad5fc4152a6df6e2069ba00cbd9e5760
7
- data.tar.gz: 6d5791fb1ffef2964f20dbfd4d15a1be7726b2f9dc3a55c6cb26fdc1dbf395bf2379761586777ca61c3ac355b40f05abc5e70643fcb80978f4322fc018c6e387
6
+ metadata.gz: 7f1ece268d4b81aebc6b6ac37654aa67dd1b5c2b0772caa7258b9aaa9bd87a2174f3fee57e2c838e61fcec4b8348762c6826e8ca29634216f0aebad534872457
7
+ data.tar.gz: adead7d121f4afa6b779b1e8fab4890d90e0423ec508b7156e30fc39e7e984e2d677f3d09ea8858dfd0b4cd711269231900e91231bfb7f1bef58018f7e601e60
@@ -1,8 +1,10 @@
1
1
  require 'httparty'
2
+ require 'nokogiri'
2
3
  require 'ncua/version'
3
4
  require 'ncua/client'
4
5
  require 'ncua/record'
5
6
  require 'ncua/credit_union'
7
+ require 'ncua/scraper'
6
8
 
7
9
  module NCUA
8
10
  def self.find_by_address(address, opts={radius: 100})
@@ -16,5 +16,13 @@ module NCUA
16
16
  field :zip, 'Zipcode'
17
17
  field(:distance_from_query_address, 'distance') { |value| nil if value < 0 }
18
18
  field(:street, 'Street', &:strip)
19
+
20
+ def munge!
21
+ @scraped_attributes ||= Scraper.new(charter_number).scrape!
22
+ end
23
+
24
+ def additional_attributes
25
+ @scraped_attributes
26
+ end
19
27
  end
20
28
  end
@@ -0,0 +1,47 @@
1
+ module NCUA
2
+ class Scraper
3
+ #This bit is as brittle as glass, as coupled as conjoined twins, and as stinky as bad cheese
4
+ include HTTParty
5
+
6
+ base_uri 'http://mapping.ncua.gov'
7
+ def initialize(charter_number)
8
+ @charter_number = charter_number
9
+ end
10
+
11
+ def scrape!
12
+ Hash[html_doc.at_css("table#MainContent_newDetails").css("tr").map do |tr|
13
+ if tr.at_css("td.dvHeader") && tr.at_css("td.dvHeader + td")
14
+ [clean_header(tr.at_css("td.dvHeader").text), clean_value(tr.at_css("td.dvHeader + td").text)]
15
+ end
16
+ end]
17
+ end
18
+
19
+ private
20
+
21
+ def clean_header(text)
22
+ text.gsub(/[,:]/,"").
23
+ gsub("/", " or ").
24
+ gsub(" ","_").
25
+ downcase.
26
+ to_sym
27
+ end
28
+
29
+ def clean_value(text)
30
+ text.gsub(/[\n\r]/,"").strip
31
+ end
32
+
33
+ def html_doc
34
+ Nokogiri::HTML(request.body)
35
+ end
36
+
37
+ def request
38
+ self.class.get(endpoint, query: {
39
+ "ID" => @charter_number
40
+ })
41
+ end
42
+
43
+ def endpoint
44
+ '/SingleResult.aspx'
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module NCUA
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_runtime_dependency "httparty", "~> 0.13"
24
+ spec.add_runtime_dependency "nokogiri", "~> 1.6.0"
24
25
  spec.add_development_dependency "bundler", "~> 1.10"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
26
27
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Reznick
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +100,7 @@ files:
86
100
  - lib/ncua/client.rb
87
101
  - lib/ncua/credit_union.rb
88
102
  - lib/ncua/record.rb
103
+ - lib/ncua/scraper.rb
89
104
  - lib/ncua/version.rb
90
105
  - ncua.gemspec
91
106
  homepage: https://github.com/ContinuityControl/ncua