Class: FreeZipcodeData::DataSource
- Inherits:
-
Object
- Object
- FreeZipcodeData::DataSource
- Defined in:
- lib/free_zipcode_data/data_source.rb
Constant Summary collapse
- BASE_URL =
'http://download.geonames.org/export/zip'
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #datafile ⇒ Object
- #download ⇒ Object
-
#initialize(country = nil) ⇒ DataSource
constructor
A new instance of DataSource.
Constructor Details
#initialize(country = nil) ⇒ DataSource
Returns a new instance of DataSource.
13 14 15 16 17 |
# File 'lib/free_zipcode_data/data_source.rb', line 13 def initialize(country = nil) @country = country @options = Options.instance.hash @logger = Logger.instance end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
11 12 13 |
# File 'lib/free_zipcode_data/data_source.rb', line 11 def country @country end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/free_zipcode_data/data_source.rb', line 11 def @options end |
Instance Method Details
#datafile ⇒ Object
28 29 30 31 32 |
# File 'lib/free_zipcode_data/data_source.rb', line 28 def datafile @datafile ||= begin datafile_with_headers end end |
#download ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/free_zipcode_data/data_source.rb', line 19 def download return nil if !.clobber && File.exist?(zipfile_path) FileUtils.mkdir_p(.work_dir) @logger.info("Downloading: #{zipfile} from GeoNames...") open(zipfile_path, 'wb') do |file| file << open("#{BASE_URL}/#{zipfile}").read end end |