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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 946e3753300232081b376667b5ab62c2f6d3fa20
4
- data.tar.gz: 2bdf2b815b91f55a0a6552653439d3748aba5228
3
+ metadata.gz: abf5512146a595a697c8e421f469242a157bd916
4
+ data.tar.gz: e055f8cc0a97a8fa2990d746ffc1e3da5a9450a2
5
5
  SHA512:
6
- metadata.gz: 734b564ad96b1580eb5e6c063bac3b1b2c21dfc870714e27932ca6fb929d5b522dd81386e38acb2b0ecdb28182438a69fe26244f68731c19053deb7771c2d407
7
- data.tar.gz: 8a9e821c303ce7700eab256304d9887b5faa05ce71e29579650b322a04f92de6487c631d78d50f3aaeb85c49f0d877e73a6a841c3762e9b89cdbd0b31b3d2cbd
6
+ metadata.gz: e85e01480ef450735468e96faa981622b48df424f1e6d8a529db61a93b9d8eecf21f78625882cbef5a66424c3b8d00f329a630e2db96d81f3b20c3cba20f024e
7
+ data.tar.gz: db1721ee4bec2632d681b9336096f182fb345eb10d84f81fa3285e0cdaaa990836cfd67408f10d6bec6d613db9f1912844c6e14d90548d6dc380db88ebcf5ad4
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+
5
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hamfinder.gemspec
4
4
  gemspec
5
+
6
+ gem 'codecov', :require => false, :group => :test
7
+
8
+ group :test do
9
+ gem 'rake'
10
+ end
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 [![Build Status](https://travis-ci.org/jasonallenphotography/HAMfinder_gem.svg?branch=master)](https://travis-ci.org/jasonallenphotography/HAMfinder_gem) [![codecov](https://codecov.io/gh/jasonallenphotography/HAMfinder_gem/branch/master/graph/badge.svg)](https://codecov.io/gh/jasonallenphotography/HAMfinder_gem)
2
2
 
3
- HAMfinder is a Ruby gem built to make developing Sinatra, Rails, and Ruby-based amateur radio programs easier to develop.
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
- TODO: Write usage instructions here
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/[USERNAME]/hamfinder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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
@@ -1,3 +1,3 @@
1
1
  module Hamfinder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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?city=#{zip}&distance=#{radius}&Dunit=m#{band}&status_id=1&use=OPEN"
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
- #queries data from Repeaterbook.com
16
+ # Captures the queried URL from Repeaterbook.com
18
17
  doc = Nokogiri::HTML(open(url))
19
18
 
20
- # scrapes dirty data <td> tags from HTML table
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.to_json
29
+ error_message[:error] = "#{error}"
27
30
  else
28
- # Sanitizes non-breaking space characters, linebreaks, and spaces throughout table data
29
- tidy_tds = sanitize(all_tds)
30
- # Organizes the data by row into an array
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
- def generate_JSON(data)
38
- output = {}
39
- data.each do |repeater|
40
- r = {frequency: "#{repeater[0]}",
41
- offset: "#{repeater[1]}",
42
- tone: "#{repeater[2]}",
43
- call: "#{repeater[3]}",
44
- location: "#{repeater[4]}",
45
- state: "#{repeater[5]}",
46
- usage: "#{repeater[6]}",
47
- voip: "#{repeater[7]}",
48
- distance: "#{repeater[8]}",
49
- direction: "#{repeater[9]}"}
50
- output[repeater[3].to_sym] = r
51
- end
52
- output
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
- def set_radius(radius)
74
- if radius > 0 && radius <= 200
75
- return radius
76
- else
77
- return 25
78
- end
79
- end
80
-
81
- def band_selection(band)
82
- case band
83
- when "10m"
84
- return "&band=29"
85
- when "6m"
86
- return "&band=5"
87
- when "2m"
88
- return "&band=14"
89
- when "1.25m"
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.0
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-13 00:00:00.000000000 Z
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