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
29 30 31 |
# File 'lib/free_zipcode_data/data_source.rb', line 29 def datafile @datafile ||= datafile_with_headers end |
#download ⇒ Object
19 20 21 22 23 24 25 26 27 |
# 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...") File.open(zipfile_path, 'wb') do |file| file << URI.parse("#{BASE_URL}/#{zipfile}").open(&:read) end end |