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.



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

def initialize(service)
  @service = service
end

Instance Attribute Details

#serviceObject

Returns the value of attribute service.



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

def service
  @service
end

Instance Method Details

#call_sign_to_id(call_sign) ⇒ Object



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

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



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

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

#resultsObject



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

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