Class: Noaaish::Fetch

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute station_id.



22
23
24
# File 'lib/noaaish/fetch.rb', line 22

def station_id
  @station_id
end

#yearObject (readonly)

Returns the value of attribute year.



22
23
24
# File 'lib/noaaish/fetch.rb', line 22

def year
  @year
end

Instance Method Details

#callObject



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_commandObject



32
33
34
# File 'lib/noaaish/fetch.rb', line 32

def curl_command
  sprintf CURL_TEMPLATE, :url => ftp_path, :destination => destination.path
end

#destinationObject



24
25
26
# File 'lib/noaaish/fetch.rb', line 24

def destination
  @destination ||= Tempfile.new("noaaish-fetch-#{station_id}")
end

#ftp_pathObject



28
29
30
# File 'lib/noaaish/fetch.rb', line 28

def ftp_path
  sprintf URL_TEMPLATE, :station_id => station_id, :year => year
end