fcc 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fm.rb DELETED
@@ -1,144 +0,0 @@
1
- require 'open-uri'
2
-
3
- module FCC
4
- class FM
5
- class Station
6
- attr_reader :call_letters, :band, :channel, :fm_status, :latitude, :longitude, :file_number, :station_class, :fcc_id, :city, :state, :country, :licensed_to
7
- def initialize(*fields)
8
- @raw = fields
9
- @call_letters = fields[0]
10
- @frequency = frequency(fields[1])
11
- @band = fields[2]
12
- @channel = fields[3]
13
- # fields[4] # Directional Antenna (DA) or NonDirectional (ND)
14
- # fields[5] # (Not Used for FM)
15
- @station_class = fields[6]
16
- # fields[7] # (Not Used for FM)
17
- @fm_status = fields[8]
18
- @city = fields[9]
19
- @state = fields[10]
20
- @country = fields[11]
21
- @file_number = fields[12] # File Number (Application, Construction Permit or License) or Docket Number (Rulemaking)
22
- @signal_strength = signal_strength(fields[13]) # Effective Radiated Power -- horizontally polarized (maximum)
23
- # fields[14] # Effective Radiated Power -- vertically polarized (maximum)
24
- # fields[15] # Antenna Height Above Average Terrain (HAAT) -- horizontal polarization
25
- # fields[16] # Antenna Height Above Average Terrain (HAAT) -- vertical polarization
26
- @fcc_id = fields[17] # Facility ID Number (unique to each station)
27
-
28
- @latitude = latitude(fields[18], fields[19], fields[20], fields[21])
29
- @longitude = longitude(fields[22], fields[23], fields[24], fields[25])
30
-
31
- @licensed_to = fields[26] # Licensee or Permittee
32
- # fields[27] # Kilometers distant (radius) from entered latitude, longitude
33
- # fields[28] # Miles distant (radius) from entered latitude, longitude
34
- # fields[29] # Azimuth, looking from center Lat, Lon to this record's Lat, Lon
35
- # fields[30] # Antenna Radiation Center Above Mean Sea Level (RCAMSL) - Horizontally Polarized - meters
36
- # fields[31] # Antenna Radiation Center Above Mean Sea Level (RCAMSL) - Vertically Polarized - meters
37
- # fields[32] # Directional Antenna ID Number
38
- # fields[33] # Directional Antenna Pattern Rotation (degrees)
39
- # fields[34] # Antenna Structure Registration Number
40
- # fields[35] # Application ID number (from CDBS database)***
41
- end
42
-
43
- def good?
44
- return false if @call_letters == "NEW"
45
- return false if @call_letters == "-"
46
- return false if @band != "FM"
47
- #@call_letters =~ /^[^0-9]/
48
-
49
- true
50
- end
51
-
52
- private
53
-
54
- def longitude(direction, degrees, minutes, seconds)
55
- "#{(direction =~ /S/ ? "-" : "")}#{degrees}.#{minutes}"
56
- end
57
-
58
- def latitude(direction, degrees, minutes, seconds)
59
- "#{(direction =~ /S/ ? "-" : "")}#{degrees}.#{minutes}"
60
- end
61
-
62
- def signal_strength(raw_signal)
63
- raw_signal.gsub(/\.\s+/, ".0 ") if raw_signal
64
- end
65
-
66
- def frequency(freq)
67
- freq[/[0-9]+\.?[0-9]/] if freq
68
- end
69
- end
70
-
71
- BASE_URL = "http://www.fcc.gov/fcc-bin/fmq"
72
-
73
- def self.find(call_letters)
74
- raise ArgumentError, "no call letters were supplied" if call_letters.nil? || call_letters.strip.length == 0
75
-
76
- find_all(:call_letters => call_letters).first
77
- end
78
-
79
- def self.find_all(conditions = {})
80
- results = []
81
- query(conditions.merge(:band => "FM")) do |feed|
82
- feed.each_line do |row|
83
- fields = row.split("|").select { |field| (field.strip! && !field.nil?)}
84
- results << Station.new(*fields)
85
- end
86
- end
87
- #remove invalid values, such as "NEW", or "-", stations starting with numbers, and non-FM bands
88
- results = results.select(&:good?)
89
- # if call letters are supplied, return matches that match call letters exactly.
90
- # FCC does a starts_with search, so that "KUT" will return "KUTT", also
91
- if conditions[:call_letters]
92
- exact_matches = results.select { |d| d.call_letters == conditions[:call_letters] }
93
- results = exact_matches if (exact_matches)
94
- end
95
-
96
- results
97
- #sort by signal strength
98
- if results.size > 1
99
- results.sort_by { |s| s.signal_strength}.reverse
100
- else
101
- results
102
- end
103
- end
104
-
105
- private
106
-
107
- def self.query(conditions = {})
108
- query = ""
109
- prepare_args(conditions).each { |k,v| query += "#{k}=#{v}&" }
110
- url = "#{BASE_URL}?#{query}"
111
- feed = open(url)
112
- yield feed
113
- end
114
-
115
- def self.prepare_args(params)
116
- return {
117
- :state => params[:state],
118
- :call => params[:call_letters],
119
- :city => params[:city],
120
- :arn => nil,
121
- :serv => params[:band],
122
- :vac => nil,
123
- :freq => params[:frequency] || params[:frequency_lower] || "0.0",
124
- :fre2 => params[:frequency] || params[:frequency_upper] || "108.0",
125
- :facid => nil,
126
- :class => nil,
127
- :dkt => nil,
128
- :dist => nil,
129
- :dlat2 => nil,
130
- :dlon2 => nil,
131
- :mlon2 => nil,
132
- :mlat2 => nil,
133
- :slat2 => nil,
134
- :slon2 => nil,
135
- # :NS => "N",
136
- # :e => 9,
137
- :EW => "W",
138
- :list => 4, # pipe separated output
139
- :size => 9
140
- }
141
- end
142
-
143
- end
144
- end
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'fcc'
16
-
17
- class Test::Unit::TestCase
18
- end
data/test/test_fcc.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFcc < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end