hamfinder 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/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +54 -0
- data/README.md +5 -10
- data/lib/hamfinder/version.rb +1 -1
- data/lib/hamfinder.rb +69 -57
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abf5512146a595a697c8e421f469242a157bd916
|
|
4
|
+
data.tar.gz: e055f8cc0a97a8fa2990d746ffc1e3da5a9450a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e85e01480ef450735468e96faa981622b48df424f1e6d8a529db61a93b9d8eecf21f78625882cbef5a66424c3b8d00f329a630e2db96d81f3b20c3cba20f024e
|
|
7
|
+
data.tar.gz: db1721ee4bec2632d681b9336096f182fb345eb10d84f81fa3285e0cdaaa990836cfd67408f10d6bec6d613db9f1912844c6e14d90548d6dc380db88ebcf5ad4
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
hamfinder (0.1.0)
|
|
5
|
+
nokogiri (~> 1.6)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
codecov (0.1.5)
|
|
11
|
+
json
|
|
12
|
+
simplecov
|
|
13
|
+
url
|
|
14
|
+
diff-lcs (1.2.5)
|
|
15
|
+
docile (1.1.5)
|
|
16
|
+
json (2.0.2)
|
|
17
|
+
mini_portile2 (2.1.0)
|
|
18
|
+
nokogiri (1.6.8)
|
|
19
|
+
mini_portile2 (~> 2.1.0)
|
|
20
|
+
pkg-config (~> 1.1.7)
|
|
21
|
+
pkg-config (1.1.7)
|
|
22
|
+
rake (10.4.2)
|
|
23
|
+
rspec (3.4.0)
|
|
24
|
+
rspec-core (~> 3.4.0)
|
|
25
|
+
rspec-expectations (~> 3.4.0)
|
|
26
|
+
rspec-mocks (~> 3.4.0)
|
|
27
|
+
rspec-core (3.4.4)
|
|
28
|
+
rspec-support (~> 3.4.0)
|
|
29
|
+
rspec-expectations (3.4.0)
|
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
+
rspec-support (~> 3.4.0)
|
|
32
|
+
rspec-mocks (3.4.1)
|
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
+
rspec-support (~> 3.4.0)
|
|
35
|
+
rspec-support (3.4.1)
|
|
36
|
+
simplecov (0.12.0)
|
|
37
|
+
docile (~> 1.1.0)
|
|
38
|
+
json (>= 1.8, < 3)
|
|
39
|
+
simplecov-html (~> 0.10.0)
|
|
40
|
+
simplecov-html (0.10.0)
|
|
41
|
+
url (0.3.2)
|
|
42
|
+
|
|
43
|
+
PLATFORMS
|
|
44
|
+
ruby
|
|
45
|
+
|
|
46
|
+
DEPENDENCIES
|
|
47
|
+
bundler (~> 1.13)
|
|
48
|
+
codecov
|
|
49
|
+
hamfinder!
|
|
50
|
+
rake
|
|
51
|
+
rspec (~> 3.0)
|
|
52
|
+
|
|
53
|
+
BUNDLED WITH
|
|
54
|
+
1.13.0
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
# HAMfinder
|
|
1
|
+
# HAMfinder [](https://travis-ci.org/jasonallenphotography/HAMfinder_gem) [](https://codecov.io/gh/jasonallenphotography/HAMfinder_gem)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
HAMfinder is a Ruby gem built to make developing Ruby on Rails-based amateur radio programs easier to develop.
|
|
4
5
|
|
|
5
6
|
Querying [Repeaterbook.com's](http://www.repeaterbook.com) data using application-defined criteria, this gem returns a collection of repeaters matching the criteria as JSON objects - conveniently named by their callsigns! For example, here is a record for a 2 meter band repeater near me in Washington, DC:
|
|
6
7
|
|
|
@@ -37,17 +38,11 @@ Or install it yourself as:
|
|
|
37
38
|
|
|
38
39
|
## Usage
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Development
|
|
43
|
-
|
|
44
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
45
|
-
|
|
46
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
41
|
+
COMING SOON! Check back after Wednesday, 14 September, 2016.
|
|
47
42
|
|
|
48
43
|
## Contributing
|
|
49
44
|
|
|
50
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jasonallenphotography/HAMfinder_gem. This project is intended to be a welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
51
46
|
|
|
52
47
|
|
|
53
48
|
## License
|
data/lib/hamfinder/version.rb
CHANGED
data/lib/hamfinder.rb
CHANGED
|
@@ -5,53 +5,74 @@ module Hamfinder
|
|
|
5
5
|
def query(options = {})
|
|
6
6
|
band = band_selection(options[:band])
|
|
7
7
|
radius = set_radius(options[:radius])
|
|
8
|
-
zip = options[:zip]
|
|
9
|
-
url = "https://www.repeaterbook.com/repeaters/prox_result.php
|
|
10
|
-
# binding.pry
|
|
8
|
+
zip = set_zip(options[:zip])
|
|
9
|
+
url = "https://www.repeaterbook.com/repeaters/prox_result.php?#{zip}#{radius}#{band}&status_id=1"
|
|
11
10
|
parse(url)
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
private
|
|
15
14
|
|
|
16
15
|
def parse(url)
|
|
17
|
-
#
|
|
16
|
+
# Captures the queried URL from Repeaterbook.com
|
|
18
17
|
doc = Nokogiri::HTML(open(url))
|
|
19
18
|
|
|
20
|
-
# scrapes dirty data
|
|
21
|
-
# source is improperly drawn without opening <tr> tags
|
|
19
|
+
# This scrapes dirty data from HTML table -
|
|
20
|
+
# the source is improperly drawn without opening <tr> tags
|
|
21
|
+
# so we collect all of the orphaned <td> children of <table>
|
|
22
22
|
all_tds = doc.xpath('//table/td').map {|content| content.text }
|
|
23
23
|
|
|
24
24
|
if all_tds.empty?
|
|
25
|
+
# Capturing error messages from the source
|
|
26
|
+
# if no results are found
|
|
27
|
+
error_message = {}
|
|
25
28
|
error = doc.xpath('//center/b').map {|content| content.text }
|
|
26
|
-
error
|
|
29
|
+
error_message[:error] = "#{error}"
|
|
27
30
|
else
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
repeater_array = organize(tidy_tds)
|
|
32
|
-
# Parse to JSON FORMAT and return
|
|
33
|
-
generate_JSON(repeater_array)
|
|
31
|
+
tidy_tds = sanitize(all_tds)
|
|
32
|
+
repeater_array = organize(tidy_tds)
|
|
33
|
+
generate_JSON(repeater_array)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
# returns band parameter for URL
|
|
38
|
+
def band_selection(band)
|
|
39
|
+
case band
|
|
40
|
+
when "10m"
|
|
41
|
+
return "&band=29"
|
|
42
|
+
when "6m"
|
|
43
|
+
return "&band=5"
|
|
44
|
+
when "2m"
|
|
45
|
+
return "&band=14"
|
|
46
|
+
when "1.25m"
|
|
47
|
+
return "&band=22"
|
|
48
|
+
when "70cm"
|
|
49
|
+
return "&band=4"
|
|
50
|
+
when "33cm"
|
|
51
|
+
return "&band=9"
|
|
52
|
+
when "23cm"
|
|
53
|
+
return "&band=12"
|
|
54
|
+
else
|
|
55
|
+
return "&band=14"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# returns only valid user-defined radius OR 25mi for radius parameter for URL
|
|
60
|
+
def set_radius(radius)
|
|
61
|
+
if radius > 0 && radius <= 200
|
|
62
|
+
return "&distance=#{radius}&Dunit=m"
|
|
63
|
+
else
|
|
64
|
+
return "&distance=25&Dunit=m"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# returns city parameter for URL
|
|
69
|
+
def set_zip(zip)
|
|
70
|
+
return "city=#{zip}"
|
|
53
71
|
end
|
|
54
72
|
|
|
73
|
+
# Sanitizes non-breaking space characters,
|
|
74
|
+
# linebreaks, and spaces throughout table data
|
|
75
|
+
# introduced by source
|
|
55
76
|
def sanitize(collection)
|
|
56
77
|
collection.each do |td|
|
|
57
78
|
td.gsub!("\u00A0", "")
|
|
@@ -60,6 +81,8 @@ module Hamfinder
|
|
|
60
81
|
end
|
|
61
82
|
end
|
|
62
83
|
|
|
84
|
+
# Organizes the data from the orphaned <td>s
|
|
85
|
+
# by row into an array
|
|
63
86
|
def organize(collection)
|
|
64
87
|
data = []
|
|
65
88
|
until collection.empty?
|
|
@@ -70,35 +93,24 @@ module Hamfinder
|
|
|
70
93
|
data
|
|
71
94
|
end
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return "&band=22"
|
|
91
|
-
when "70cm"
|
|
92
|
-
return "&band=4"
|
|
93
|
-
when "33cm"
|
|
94
|
-
return "&band=9"
|
|
95
|
-
when "23cm"
|
|
96
|
-
return "&band=12"
|
|
97
|
-
else
|
|
98
|
-
return "&band=14"
|
|
99
|
-
end
|
|
96
|
+
# Parse to JSON FORMAT and return
|
|
97
|
+
def generate_JSON(data)
|
|
98
|
+
output = {}
|
|
99
|
+
data.each do |repeater|
|
|
100
|
+
r = {frequency: "#{repeater[0]}",
|
|
101
|
+
offset: "#{repeater[1]}",
|
|
102
|
+
tone: "#{repeater[2]}",
|
|
103
|
+
call: "#{repeater[3]}",
|
|
104
|
+
location: "#{repeater[4]}",
|
|
105
|
+
state: "#{repeater[5]}",
|
|
106
|
+
usage: "#{repeater[6]}",
|
|
107
|
+
voip: "#{repeater[7]}",
|
|
108
|
+
distance: "#{repeater[8]}",
|
|
109
|
+
direction: "#{repeater[9]}"}
|
|
110
|
+
output[repeater[3].to_sym] = r
|
|
111
|
+
end
|
|
112
|
+
output
|
|
100
113
|
end
|
|
101
114
|
|
|
102
115
|
end #parser
|
|
103
|
-
|
|
104
116
|
end #module
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hamfinder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Allen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-09-
|
|
11
|
+
date: 2016-09-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|
|
@@ -76,8 +76,10 @@ extensions: []
|
|
|
76
76
|
extra_rdoc_files: []
|
|
77
77
|
files:
|
|
78
78
|
- ".gitignore"
|
|
79
|
+
- ".travis.yml"
|
|
79
80
|
- CODE_OF_CONDUCT.md
|
|
80
81
|
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
81
83
|
- LICENSE.txt
|
|
82
84
|
- README.md
|
|
83
85
|
- Rakefile
|