Class: ZipGeoJp::Downloader
- Inherits:
-
Object
- Object
- ZipGeoJp::Downloader
- Defined in:
- lib/zip_geo_jp/downloader.rb
Instance Attribute Summary collapse
-
#local_dir ⇒ Object
Returns the value of attribute local_dir.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #download ⇒ Object
- #downloaded? ⇒ Boolean
- #filename ⇒ Object
-
#initialize(url, local_dir) ⇒ Downloader
constructor
A new instance of Downloader.
- #local ⇒ Object
- #remove ⇒ Object
Constructor Details
#initialize(url, local_dir) ⇒ Downloader
Returns a new instance of Downloader.
8 9 10 11 |
# File 'lib/zip_geo_jp/downloader.rb', line 8 def initialize(url, local_dir) @url = url @local_dir = local_dir end |
Instance Attribute Details
#local_dir ⇒ Object
Returns the value of attribute local_dir.
6 7 8 |
# File 'lib/zip_geo_jp/downloader.rb', line 6 def local_dir @local_dir end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/zip_geo_jp/downloader.rb', line 6 def url @url end |
Instance Method Details
#download ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/zip_geo_jp/downloader.rb', line 29 def download FileUtils.mkdir_p(@local_dir) open(@url) do |stream| open(local, 'w+b') do |file| file.write(stream.read) end end end |
#downloaded? ⇒ Boolean
25 26 27 |
# File 'lib/zip_geo_jp/downloader.rb', line 25 def downloaded? File.exist? local end |
#filename ⇒ Object
13 14 15 |
# File 'lib/zip_geo_jp/downloader.rb', line 13 def filename @filename ||= URI.parse(url).path.to_s.split('/').last end |
#local ⇒ Object
17 18 19 |
# File 'lib/zip_geo_jp/downloader.rb', line 17 def local File.join(@local_dir, filename) end |
#remove ⇒ Object
21 22 23 |
# File 'lib/zip_geo_jp/downloader.rb', line 21 def remove FileUtils.remove_file local if File.exist? local end |