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.
'ftp://wirelessftp.fcc.gov/pub/uls/daily'.freeze
- WEEKLY_BASE_URL =
'ftp://wirelessftp.fcc.gov/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.
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
#service ⇒ Object
Returns the value of attribute service.
27 28 29 |
# File 'lib/uls/retriever.rb', line 27 def service @service end |
Class Method Details
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
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 |
#services ⇒ Object
72 73 74 |
# File 'lib/uls/retriever.rb', line 72 def services SERVICES.keys end |
#types ⇒ Object
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
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 |