hamfinder 0.1.2 → 0.2.2
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 +4 -3
- data/README.md +59 -2
- data/hamfinder.gemspec +2 -1
- data/lib/hamfinder.rb +14 -11
- data/lib/hamfinder/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe4d63b3c0d14740d88adb2fa45e50b15339d809
|
|
4
|
+
data.tar.gz: aedd8fa4043c82027aa00d49951b8e15b2f17dfd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 107e3a50229ca9236f097892f6754f3cca24d807e6aa4a295b1189978b2e85185f693850ec91748c7052c6b122e9a40e720bc2e67695b95e593925f055f547ee
|
|
7
|
+
data.tar.gz: 0d736a56ea51150e63193b81141d8a20d98fff2525263ae8d4a86ca6e427869c9a1a941a8b819ca4f98ec8c75225a560ba88641330f2af840d38561e1ed8f0a7
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
hamfinder (0.
|
|
4
|
+
hamfinder (0.2.2)
|
|
5
|
+
json (~> 1.8)
|
|
5
6
|
nokogiri (~> 1.6)
|
|
6
7
|
|
|
7
8
|
GEM
|
|
@@ -13,13 +14,13 @@ GEM
|
|
|
13
14
|
url
|
|
14
15
|
diff-lcs (1.2.5)
|
|
15
16
|
docile (1.1.5)
|
|
16
|
-
json (
|
|
17
|
+
json (1.8.3)
|
|
17
18
|
mini_portile2 (2.1.0)
|
|
18
19
|
nokogiri (1.6.8)
|
|
19
20
|
mini_portile2 (~> 2.1.0)
|
|
20
21
|
pkg-config (~> 1.1.7)
|
|
21
22
|
pkg-config (1.1.7)
|
|
22
|
-
rake (11.
|
|
23
|
+
rake (11.3.0)
|
|
23
24
|
rspec (3.5.0)
|
|
24
25
|
rspec-core (~> 3.5.0)
|
|
25
26
|
rspec-expectations (~> 3.5.0)
|
data/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
# HAMfinder [](https://travis-ci.org/jasonallenphotography/HAMfinder_gem) [](https://codecov.io/gh/jasonallenphotography/HAMfinder_gem)
|
|
1
|
+
# HAMfinder [](https://travis-ci.org/jasonallenphotography/HAMfinder_gem) [](https://codecov.io/gh/jasonallenphotography/HAMfinder_gem) [](https://badge.fury.io/rb/hamfinder) [](https://gemnasium.com/github.com/jasonallenphotography/HAMfinder_gem)
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
HAMfinder is a Ruby gem built to make developing Ruby on Rails-based amateur radio programs easier to develop.
|
|
@@ -38,7 +39,63 @@ Or install it yourself as:
|
|
|
38
39
|
|
|
39
40
|
## Usage
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
When using HAMfinder, you must first instantiate a new parser in your application:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
parser = Hamfinder::Parser.new
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Now you can use your parser's query method to retrieve data according to your provided parameters.
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
@results = parser.query( zip:"11232", radius:5, band:"2m" )
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The `.query()` method accepts the following options:
|
|
55
|
+
* zip
|
|
56
|
+
* radius
|
|
57
|
+
* band
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
The `zip` parameter must be a valid 5 digit US postal zip code passed as a string (i.e. `zip:"22181"`).
|
|
61
|
+
|
|
62
|
+
The `radius` parameter (in miles) must be an integer greater than 0 and less than or equal to 200 (i.e. `radius:50`). If no radius is entered as a parameter the default is a radius of 10 miles, roughly the maximum distance a low powered handheld radio can reach on 2m band.
|
|
63
|
+
|
|
64
|
+
The `band` parameter specifies the frequency band you wish to query, and must be passed as a string. `band` accepts the following values, or defaults to `2m`:
|
|
65
|
+
* `"10m"`
|
|
66
|
+
* `"6m"`
|
|
67
|
+
* `"2m"`
|
|
68
|
+
* `"1.25m"`
|
|
69
|
+
* `"70cm"`
|
|
70
|
+
* `"33cm"`
|
|
71
|
+
* `"23cm"`
|
|
72
|
+
|
|
73
|
+
Examples of output:
|
|
74
|
+
```ruby
|
|
75
|
+
#10m band repeaters within 5 miles of 20009, Washington DC
|
|
76
|
+
puts parser.query( zip:"20009", band:"10m", radius:5 )
|
|
77
|
+
=> ["NO REPEATERS FOUND WITHIN 5 MILES of 38.9191485, -77.0362967."]
|
|
78
|
+
|
|
79
|
+
#2m band repeaters within 2 miles of 20009, Washington DC
|
|
80
|
+
puts parser.query( zip:"20009", radius:2 )
|
|
81
|
+
=> { :W3DOS=>{:frequency=>"145.1900", :offset=>"-0.6MHz", :tone=>"151.4", :call=>"W3DOS",
|
|
82
|
+
:location=>"Washington,HarryS.TrumanBuilding", :state=>"DC", :usage=>"OPEN",
|
|
83
|
+
:voip=>"", :distance=>"1.7", :direction=>"S"},
|
|
84
|
+
:W3AGB=>{:frequency=>"147.3600", :offset=>"+0.6MHz", :tone=>"", :call=>"W3AGB",
|
|
85
|
+
:location=>"Washington", :state=>"DC", :usage=>"OPEN",
|
|
86
|
+
:voip=>"", :distance=>"1.7", :direction=>"S"},
|
|
87
|
+
:K4DCA=>{:frequency=>"145.1100", :offset=>"-0.6MHz", :tone=>"CC1", :call=>"K4DCA",
|
|
88
|
+
:location=>"Washington", :state=>"DC", :usage=>"OPEN",
|
|
89
|
+
:voip=>"", :distance=>"0.8", :direction=>"S"},
|
|
90
|
+
:K3MRC=>{:frequency=>"145.4300", :offset=>"-0.6MHz", :tone=>"114.8", :call=>"K3MRC",
|
|
91
|
+
:location=>"Washington,D.C.", :state=>"DC", :usage=>"OPEN",
|
|
92
|
+
:voip=>"", :distance=>"1.7", :direction=>"S"} }
|
|
93
|
+
|
|
94
|
+
#2m band repeaters within a default 10 miles of 20009, Washington DC
|
|
95
|
+
puts parser.query( zip:"20009" )
|
|
96
|
+
=> {:W4HFH=>{:frequency=>"147.3150", :offset=>"+0.6MHz", :tone=>"107.2", :call=>"W4HFH",
|
|
97
|
+
...
|
|
98
|
+
```
|
|
42
99
|
|
|
43
100
|
## Contributing
|
|
44
101
|
|
data/hamfinder.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ["jasoncaryallen@gmail.com"]
|
|
11
11
|
|
|
12
12
|
spec.summary = %q{Return queried HAM radio repeater stations}
|
|
13
|
-
spec.description = %q{Querying Repeaterbook.com's data using application-defined criteria, this gem returns a collection of repeaters matching the criteria as JSON
|
|
13
|
+
spec.description = %q{Querying Repeaterbook.com's data using application-defined criteria, this gem returns a collection of repeaters matching the criteria as JSON - conveniently sorted by proximity!}
|
|
14
14
|
spec.homepage = "https://github.com/jasonallenphotography/HAMfinder_gem"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
31
|
spec.require_paths = ["lib"]
|
|
32
32
|
|
|
33
|
+
spec.add_dependency("json", "~> 1.8")
|
|
33
34
|
spec.add_dependency("nokogiri", "~> 1.6")
|
|
34
35
|
spec.add_development_dependency "bundler", "~> 1.13"
|
|
35
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/hamfinder.rb
CHANGED
|
@@ -2,7 +2,7 @@ require "hamfinder/version"
|
|
|
2
2
|
|
|
3
3
|
module Hamfinder
|
|
4
4
|
class Parser
|
|
5
|
-
def query(options = {})
|
|
5
|
+
def self.query(options = {})
|
|
6
6
|
band = band_selection(options[:band])
|
|
7
7
|
options[:radius] ? radius = set_radius(options[:radius]) : radius = "&distance=10&Dunit=m"
|
|
8
8
|
zip = set_zip(options[:zip])
|
|
@@ -12,7 +12,7 @@ module Hamfinder
|
|
|
12
12
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
|
-
def parse(url)
|
|
15
|
+
def self.parse(url)
|
|
16
16
|
# Captures the queried URL from Repeaterbook.com
|
|
17
17
|
doc = Nokogiri::HTML(open(url))
|
|
18
18
|
|
|
@@ -30,12 +30,13 @@ module Hamfinder
|
|
|
30
30
|
else
|
|
31
31
|
tidy_tds = sanitize(all_tds)
|
|
32
32
|
repeater_array = organize(tidy_tds)
|
|
33
|
+
repeater_array.sort! {|x,y| x[8].to_f <=> y[8].to_f }
|
|
33
34
|
generate_JSON(repeater_array)
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
# returns band parameter for URL
|
|
38
|
-
def band_selection(band)
|
|
39
|
+
def self.band_selection(band)
|
|
39
40
|
case band
|
|
40
41
|
when "10m"
|
|
41
42
|
return "&band=29"
|
|
@@ -57,7 +58,7 @@ module Hamfinder
|
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
# returns only valid user-defined radius OR 25mi for radius parameter for URL
|
|
60
|
-
def set_radius(radius)
|
|
61
|
+
def self.set_radius(radius)
|
|
61
62
|
if radius > 0 && radius <= 200
|
|
62
63
|
return "&distance=#{radius}&Dunit=m"
|
|
63
64
|
else
|
|
@@ -66,14 +67,14 @@ module Hamfinder
|
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
# returns city parameter for URL
|
|
69
|
-
def set_zip(zip)
|
|
70
|
+
def self.set_zip(zip)
|
|
70
71
|
return "city=#{zip}"
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
# Sanitizes non-breaking space characters,
|
|
74
75
|
# linebreaks, and spaces throughout table data
|
|
75
76
|
# introduced by source
|
|
76
|
-
def sanitize(collection)
|
|
77
|
+
def self.sanitize(collection)
|
|
77
78
|
collection.each do |td|
|
|
78
79
|
td.gsub!("\u00A0", "")
|
|
79
80
|
td.gsub!("\n", "")
|
|
@@ -83,7 +84,7 @@ module Hamfinder
|
|
|
83
84
|
|
|
84
85
|
# Organizes the data from the orphaned <td>s
|
|
85
86
|
# by row into an array
|
|
86
|
-
def organize(collection)
|
|
87
|
+
def self.organize(collection)
|
|
87
88
|
data = []
|
|
88
89
|
until collection.empty?
|
|
89
90
|
row = collection.shift(11)
|
|
@@ -94,8 +95,9 @@ module Hamfinder
|
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
# Parse to JSON FORMAT and return
|
|
97
|
-
def generate_JSON(data)
|
|
98
|
+
def self.generate_JSON(data)
|
|
98
99
|
output = {}
|
|
100
|
+
index = 0
|
|
99
101
|
data.each do |repeater|
|
|
100
102
|
r = {frequency: "#{repeater[0]}",
|
|
101
103
|
offset: "#{repeater[1]}",
|
|
@@ -107,10 +109,11 @@ module Hamfinder
|
|
|
107
109
|
voip: "#{repeater[7]}",
|
|
108
110
|
distance: "#{repeater[8]}",
|
|
109
111
|
direction: "#{repeater[9]}"}
|
|
110
|
-
output[
|
|
112
|
+
output[index.to_s.to_sym] = r
|
|
113
|
+
index +=1
|
|
111
114
|
end
|
|
112
|
-
output
|
|
115
|
+
output.to_json
|
|
113
116
|
end
|
|
114
117
|
|
|
115
118
|
end #parser
|
|
116
|
-
end #module
|
|
119
|
+
end #module
|
data/lib/hamfinder/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hamfinder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.2
|
|
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-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: json
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: nokogiri
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,8 +81,8 @@ dependencies:
|
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
82
|
version: '3.0'
|
|
69
83
|
description: Querying Repeaterbook.com's data using application-defined criteria,
|
|
70
|
-
this gem returns a collection of repeaters matching the criteria as JSON
|
|
71
|
-
|
|
84
|
+
this gem returns a collection of repeaters matching the criteria as JSON - conveniently
|
|
85
|
+
sorted by proximity!
|
|
72
86
|
email:
|
|
73
87
|
- jasoncaryallen@gmail.com
|
|
74
88
|
executables: []
|