Class: DwcaHunter::Resource
- Inherits:
-
Object
- Object
- DwcaHunter::Resource
- Defined in:
- lib/dwca_hunter/resource.rb
Direct Known Subclasses
ResourceAOS, ResourceArctos, ResourceBirdLife, ResourceClements, ResourceEOL, ResourceFishbase, ResourceFreebase, ResourceHowardMoore, ResourceIOCWorldBird, ResourceION, ResourceIPNI, ResourceITIS, ResourceMCZ, ResourceMammalDiversityDb, ResourceMammalSpecies, ResourceNCBI, ResourceOpenTree, ResourcePaleoBioDb, ResourceReptilesChecklist, ResourceSherborn, ResourceWikispecies
Instance Attribute Summary collapse
-
#abbr ⇒ Object
readonly
Returns the value of attribute abbr.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#download_path ⇒ Object
readonly
Returns the value of attribute download_path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(opts) ⇒ Resource
constructor
A new instance of Resource.
- #needs_download? ⇒ Boolean
- #needs_unpack? ⇒ Boolean
Constructor Details
#initialize(opts) ⇒ Resource
Returns a new instance of Resource.
15 16 17 18 19 20 |
# File 'lib/dwca_hunter/resource.rb', line 15 def initialize(opts) @needs_download = !(opts[:download] == false) @needs_unpack = !(opts[:unpack] == false) @download_dir, @download_file = File.split(@download_path) prepare_path if needs_download? end |
Instance Attribute Details
#abbr ⇒ Object (readonly)
Returns the value of attribute abbr.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def abbr @abbr end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def command @command end |
#download_path ⇒ Object (readonly)
Returns the value of attribute download_path.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def download_path @download_path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def url @url end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
3 4 5 |
# File 'lib/dwca_hunter/resource.rb', line 3 def uuid @uuid end |
Class Method Details
.gunzip(file, dir = nil) ⇒ Object
10 11 12 13 |
# File 'lib/dwca_hunter/resource.rb', line 10 def self.gunzip(file, dir = nil) Dir.chdir(dir) if dir `gunzip #{file}` end |
.unzip(file, dir = nil) ⇒ Object
5 6 7 8 |
# File 'lib/dwca_hunter/resource.rb', line 5 def self.unzip(file, dir = nil) Dir.chdir(dir) if dir `unzip -qq -u #{file} > /dev/null 2>&1` end |
Instance Method Details
#download ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dwca_hunter/resource.rb', line 30 def download DwcaHunter::logger_write(self.object_id, "Starting download of '%s'" % @url) percentage = 0 if url.match(/^\s*http:\/\//) dlr = DwcaHunter::Downloader.new(url, @download_path) downloaded_length = dlr.download_with_percentage do |r| if r[:percentage].to_i != percentage percentage = r[:percentage].to_i msg = "Downloaded %.0f%% in %.0f seconds ETA is %.0f seconds" % [percentage, r[:elapsed_time], r[:eta]] DwcaHunter::logger_write(self.object_id, msg) end end DwcaHunter::logger_write(self.object_id, "Download finished, Size: %s" % downloaded_length) else `curl -s #{url} > #{download_path}` end end |
#needs_download? ⇒ Boolean
22 23 24 |
# File 'lib/dwca_hunter/resource.rb', line 22 def needs_download? @needs_download end |
#needs_unpack? ⇒ Boolean
26 27 28 |
# File 'lib/dwca_hunter/resource.rb', line 26 def needs_unpack? @needs_unpack end |