Class: Noaaish::Fetch
- Inherits:
-
Object
- Object
- Noaaish::Fetch
- Defined in:
- lib/noaaish/fetch.rb
Constant Summary collapse
- URL_TEMPLATE =
'ftp://ftp.ncdc.noaa.gov/pub/data/noaa/%<year>s/%<station_id>s-%<year>s.gz'.freeze
- CURL_TEMPLATE =
'curl -o %<destination>s %<url>s'
Instance Attribute Summary collapse
-
#station_id ⇒ Object
readonly
Returns the value of attribute station_id.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #call ⇒ Object
- #curl_command ⇒ Object
- #destination ⇒ Object
- #ftp_path ⇒ Object
-
#initialize(station_id, year) ⇒ Fetch
constructor
A new instance of Fetch.
Constructor Details
#initialize(station_id, year) ⇒ Fetch
Returns a new instance of Fetch.
11 12 13 14 |
# File 'lib/noaaish/fetch.rb', line 11 def initialize(station_id, year) @station_id = station_id @year = year end |
Instance Attribute Details
#station_id ⇒ Object (readonly)
Returns the value of attribute station_id.
22 23 24 |
# File 'lib/noaaish/fetch.rb', line 22 def station_id @station_id end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
22 23 24 |
# File 'lib/noaaish/fetch.rb', line 22 def year @year end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 |
# File 'lib/noaaish/fetch.rb', line 16 def call result = system(curl_command) raise "Failed calling #{curl_command}" unless result destination end |
#curl_command ⇒ Object
32 33 34 |
# File 'lib/noaaish/fetch.rb', line 32 def curl_command sprintf CURL_TEMPLATE, :url => ftp_path, :destination => destination.path end |
#destination ⇒ Object
24 25 26 |
# File 'lib/noaaish/fetch.rb', line 24 def destination @destination ||= Tempfile.new("noaaish-fetch-#{station_id}") end |
#ftp_path ⇒ Object
28 29 30 |
# File 'lib/noaaish/fetch.rb', line 28 def ftp_path sprintf URL_TEMPLATE, :station_id => station_id, :year => year end |