Class: FCC::Station::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/fcc/station/result.rb

Constant Summary collapse

EXTENDED_ATTRIBUTES =

these take a long time to query

%i[band signal_strength latitude longitude station_class file_number effective_radiated_power haat_horizontal haat_vertical antenna_type operating_hours licensed_to city state country]
BASIC_ATTRIBUTES =
%i[id call_sign status rf_channel license_expiration_date facility_type frequency band]

Instance Method Summary collapse

Constructor Details

#initialize(service, call_sign, options = {}) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
# File 'lib/fcc/station/result.rb', line 9

def initialize(service, call_sign, options = {})
  @call_sign = call_sign.upcase
  @service = service
  @options = options

  data

  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *_args) ⇒ Object (private)



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/fcc/station/result.rb', line 160

def method_missing(m, *_args)
  service = if @service == :fm
              fm_record = grouped_records.find { |gr| FCC::FM_FULL_SERVICE == gr.band.upcase }
              fm_low_power = grouped_records.find { |gr| FCC::FM_LOW_POWER == gr.band.upcase }
              fm_booster = grouped_records.find { |gr| FCC::FM_BOOSTER == gr.band.upcase }
              fm_translator = grouped_records.find { |gr| FCC::FM_TRANSLATOR == gr.band.upcase }

              [fm_record, fm_low_power, fm_booster, fm_translator].compact.find { |r| r.send(m.to_sym) }
            else
              grouped_records.find { |r| r.send(m.to_sym) }
            end

  result = service.send(m.to_sym) if service

  result = result.first if result.is_a?(Array) && result.size == 1

  result
end

Instance Method Details

#all_recordsObject



69
70
71
# File 'lib/fcc/station/result.rb', line 69

def all_records
  [public_records, transition_records, related_translators].flatten.compact.filter { |f| f.has_data? }
end

#call_signs_match?(ours, theirs) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/fcc/station/result.rb', line 132

def call_signs_match?(ours, theirs)
  theirs.to_s.upcase.to_s == ours.to_s.upcase.to_s || theirs.to_s.upcase =~ Regexp.new("^#{ours.to_s.upcase}[-—–][A-Z0-9]+$")
end

#coordinates_urlObject



39
40
41
# File 'lib/fcc/station/result.rb', line 39

def coordinates_url
  "https://www.google.com/maps/search/#{latitude},#{longitude}" if latitude.present? && longitude.present?
end

#dataObject Also known as: public_data



51
52
53
# File 'lib/fcc/station/result.rb', line 51

def data
  @data ||= RecordDelegate.new(Info.new(@service).find(@call_sign))
end

#details_available?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/fcc/station/result.rb', line 19

def details_available?
  exists? && data.latitude.present?
end

#enterprise_data_urlObject



47
48
49
# File 'lib/fcc/station/result.rb', line 47

def enterprise_data_url
  "https://enterpriseefiling.fcc.gov/dataentry/public/tv/publicFacilityDetails.html?facilityId=#{id}"
end

#exists?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/fcc/station/result.rb', line 27

def exists?
  grouped_records.any?
end

#extended_data_urlObject



43
44
45
# File 'lib/fcc/station/result.rb', line 43

def extended_data_url
  "https://transition.fcc.gov/fcc-bin/#{@service.to_s.downcase}q?list=4&facid=#{id}"
end

#grouped_recordsObject Also known as: records



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fcc/station/result.rb', line 56

def grouped_records
  grouped = all_records.group_by do |record|
    [record.id, record.call_sign, record.band, record.frequency].compact.join('/')
  end

  [].tap do |res|
    grouped.each do |_key, values|
      res << RecordGroup.new(values)
    end
  end
end

#licensed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/fcc/station/result.rb', line 23

def licensed?
  exists? && data.status == 'LICENSED' && data.license_expiration_date && Time.parse(data.license_expiration_date) > Time.now
end

#lms_dataObject



128
129
130
# File 'lib/fcc/station/result.rb', line 128

def lms_data
  @lms_data ||= LmsData.new
end


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fcc/station/result.rb', line 104

def print_broadcast_summary
  FCC.log "[primary]"
  transition_records.each do |record|
    FCC.log "[#{record.band}] #{record.frequency} #{record.call_sign}#{record.community.city} #{record.community.state}"
  end

  FCC.log "[translators]"
  related_translators.each do |record|
    FCC.log "[#{record.band}] #{record.frequency} #{record.call_sign}#{record.community.city} #{record.community.state}"
  end

  FCC.log "[related stations]"
  related_stations.each do |record|
    FCC.log "[#{record.band}] #{record.frequency} #{record.call_sign}#{record.community.city} #{record.community.state}"
  end

  FCC.log "[all related]"
  related.each do |record|
    FCC.log "[#{record.band}] #{record.frequency} #{record.call_sign}#{record.community.city} #{record.community.state}"
  end

  nil
end


93
94
95
96
97
98
99
100
101
102
# File 'lib/fcc/station/result.rb', line 93

def related
  @related ||= begin
    records = lms_data.find_all_related(call_sign: @call_sign)
    records.keys.map do |call|
      ExtendedInfo.new(@service).find(call).collect do |info|
        RecordDelegate.new(info)
      end
    end.flatten.select { |f| f.status.upcase == "LIC" }
  end
end


84
85
86
87
88
89
90
91
# File 'lib/fcc/station/result.rb', line 84

def related_stations
  @related_stations ||= begin
    records = lms_data.find_related_stations(call_sign: @call_sign)
    records.keys.map do |call|
      RecordDelegate.new(ExtendedInfo.new(@service).find(call))
    end.select { |f| f.status.upcase == "LIC" }      
  end
end


73
74
75
76
77
78
79
80
81
82
# File 'lib/fcc/station/result.rb', line 73

def related_translators
  @related_translators ||= begin
    records = lms_data.find_translators_for(call_sign: @call_sign)
    records.keys.map do |call|
      RecordDelegate.new(ExtendedInfo.new(@service).find(call))
    end.select { |f| f.status.upcase == "LIC" }
  rescue
    []
  end
end

#to_json(*_args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/fcc/station/result.rb', line 31

def to_json(*_args)
  [].tap do |records|
    grouped_records.each do |rg|
      records << rg.to_json
    end
  end.flatten.compact.uniq
end