Class: ULS::Retriever
- Inherits:
-
Object
- Object
- ULS::Retriever
- 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.
'https://data.fcc.gov/download/pub/uls/daily'.freeze
- WEEKLY_BASE_URL =
'https://data.fcc.gov/download/pub/uls/complete'.freeze
Instance Attribute Summary collapse
-
#service ⇒ Object
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #daily(type, wday = Date.new.prev_day.wday) ⇒ Object
- #daily_url(type, wday = Date.new.prev_day.wday) ⇒ Object
-
#initialize(service) ⇒ Retriever
constructor
A new instance of Retriever.
- #services ⇒ Object
- #types ⇒ Object
- #weekly(type) ⇒ Object
- #weekly_url(type) ⇒ Object
Constructor Details
#initialize(service) ⇒ Retriever
Returns a new instance of Retriever.
34 35 36 37 38 |
# File 'lib/uls/retriever.rb', line 34 def initialize(service) raise ArgumentError, "Invalid service #{service}" unless services.include?(service) self.service = service end |
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
28 29 30 |
# File 'lib/uls/retriever.rb', line 28 def service @service end |
Class Method Details
Instance Method Details
#daily(type, wday = Date.new.prev_day.wday) ⇒ Object
64 65 66 67 |
# File 'lib/uls/retriever.rb', line 64 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/uls/retriever.rb', line 54 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 |
#services ⇒ Object
73 74 75 |
# File 'lib/uls/retriever.rb', line 73 def services SERVICES.keys end |
#types ⇒ Object
69 70 71 |
# File 'lib/uls/retriever.rb', line 69 def types SERVICES[service][:records].keys end |
#weekly(type) ⇒ Object
49 50 51 52 |
# File 'lib/uls/retriever.rb', line 49 def weekly(type) url = weekly_url(type) download(url) end |
#weekly_url(type) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/uls/retriever.rb', line 40 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 |