Class: ULS::Retriever

Inherits:
Object
  • Object
show all
Defined in:
lib/uls/retriever.rb

Constant Summary collapse

APPLICATION_PREFIX =
'a'.freeze
LICENSE_PREFIX =
'l'.freeze
SERVICES =
{
  amateur_radio: {
    filename: {
      daily: 'am',
      weekly: 'amat'
    },
    records: {
      applications: APPLICATION_PREFIX,
      licenses: LICENSE_PREFIX
    }
  }
}.freeze
DAILY_BASE_URL =

Different base URLs whether we’re looking for the daily updates or the full weekly downloads.

'ftp://wirelessftp.fcc.gov/pub/uls/daily'.freeze
WEEKLY_BASE_URL =
'ftp://wirelessftp.fcc.gov/pub/uls/complete'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Retriever

Returns a new instance of Retriever.

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/uls/retriever.rb', line 33

def initialize(service)
  raise ArgumentError, "Invalid service #{service}" unless services.include?(service)

  self.service = service
end

Instance Attribute Details

#serviceObject

Returns the value of attribute service.



27
28
29
# File 'lib/uls/retriever.rb', line 27

def service
  @service
end

Class Method Details

.amateur_radioObject



29
30
31
# File 'lib/uls/retriever.rb', line 29

def self.amateur_radio
  Retriever.new(:amateur_radio)
end

Instance Method Details

#daily(type, wday = Date.new.prev_day.wday) ⇒ Object



63
64
65
66
# File 'lib/uls/retriever.rb', line 63

def daily(type, wday = Date.new.prev_day.wday)
  url = daily_url(type, wday)
  download(url)
end

#daily_url(type, wday = Date.new.prev_day.wday) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
# File 'lib/uls/retriever.rb', line 53

def daily_url(type, wday = Date.new.prev_day.wday)
  raise ArgumentError, "Invalid type #{type}" unless types.include?(type)

  abbreviated_day = Date::ABBR_DAYNAMES[wday].downcase
  prefix = SERVICES[service][:records][type]
  name = SERVICES[service][:filename][:daily]

  "#{DAILY_BASE_URL}/#{prefix}_#{name}_#{abbreviated_day}.zip"
end

#servicesObject



72
73
74
# File 'lib/uls/retriever.rb', line 72

def services
  SERVICES.keys
end

#typesObject



68
69
70
# File 'lib/uls/retriever.rb', line 68

def types
  SERVICES[service][:records].keys
end

#weekly(type) ⇒ Object



48
49
50
51
# File 'lib/uls/retriever.rb', line 48

def weekly(type)
  url = weekly_url(type)
  download(url)
end

#weekly_url(type) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
# File 'lib/uls/retriever.rb', line 39

def weekly_url(type)
  raise ArgumentError, "Invalid type #{type}" unless types.include?(type)

  prefix = SERVICES[service][:records][type]
  name = SERVICES[service][:filename][:weekly]

  "#{WEEKLY_BASE_URL}/#{prefix}_#{name}.zip"
end