Class: FCC::Station::Index

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Index

Returns a new instance of Index.



11
12
13
# File 'lib/fcc/station/index.rb', line 11

def initialize(service)
  @service = service
end

Instance Attribute Details

#serviceObject

Returns the value of attribute service.



9
10
11
# File 'lib/fcc/station/index.rb', line 9

def service
  @service
end

Instance Method Details

#call_sign_to_id(call_sign) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fcc/station/index.rb', line 15

def call_sign_to_id(call_sign)
  found = results.detect do |hash|
    hash['callSign'] == call_sign.upcase
  end

  found ||= results.detect do |hash|
    hash['callSign'] == "#{call_sign.upcase}-#{service.to_s.upcase}"
  end

  found['id'] if found
end

#inspectObject



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

def inspect
  "<Station::Index @results=[#{results.size}]>"
end

#resultsObject



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

def results
  @results ||= begin
    response = self.class.get("/api/service/#{service.to_s.downcase}/facility/getall.json")
    response.parsed_response['results']['facilityList']
  end
end