Class: FCC::Station::ExtendedInfo

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fcc/station/extended_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ ExtendedInfo

Returns a new instance of ExtendedInfo.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fcc/station/extended_info.rb', line 12

def initialize(service)
  @service = service
  @options = {
    follow_redirects: true
  }
  
  @query = {
    # state: nil,
    # call: nil,
    # city: nil,
    # arn: nil,
    # serv: service.to_s.downcase, # Only return primary main records, no backup transmitters, etc… for now
    status: 3, # licensed records only
    # freq: @service.to_sym == :fm ? '87.1' : '530',
    # fre2: @service.to_sym == :fm ? '107.9' : '1700',
    # facid: nil,
    # class: nil,
    # dkt:   nil,
    # dist:  nil,
    # dlat2: nil,
    # dlon2: nil,
    # mlon2: nil,
    # mlat2: nil,
    # slat2: nil,
    # slon2: nil,
    # NS: "N",
    # e: 9,
    # EW: 'W',
    list: 4, # pipe separated output
    size: 9
  }
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



8
9
10
# File 'lib/fcc/station/extended_info.rb', line 8

def results
  @results
end

#serviceObject

Returns the value of attribute service.



8
9
10
# File 'lib/fcc/station/extended_info.rb', line 8

def service
  @service
end

Instance Method Details

#all_resultsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fcc/station/extended_info.rb', line 45

def all_results

  begin
    cache_key = "#{self.class.instance_variable_get('@default_options')[:base_uri]}/#{@service.to_s.downcase}q"
    FCC.cache.fetch cache_key do
      response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query))
      FCC.log(response.request.uri.to_s.gsub('&list=4', '&list=0'))
      response.parsed_response
    end
  rescue StandardError => e
    FCC.error(e.message)
    FCC.error(e.backtrace)
  end
end

#find(id_or_call_sign) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/fcc/station/extended_info.rb', line 60

def find(id_or_call_sign)
  if id_or_call_sign =~ /^\d+$/
    id = id_or_call_sign
    all_results.filter { |r| r[:fcc_id].to_s == id.to_s } || find_directly({ facid: id_or_call_sign })
  else
    all_results.filter { |r| 
      r[:call_sign].to_s == id_or_call_sign.to_s || r[:call_sign].to_s.upcase =~ Regexp.new("^#{id_or_call_sign.upcase}[-—–][A-Z0-9]+$")
    } || find_directly({ call: id_or_call_sign })
  end
end

#find_directly(options) ⇒ Object



71
72
73
74
75
# File 'lib/fcc/station/extended_info.rb', line 71

def find_directly(options)
  response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query.merge(options)))
  FCC.log response.request.uri.to_s.gsub('&list=4', '&list=0')
  response.parsed_response
end