download 0.0.1.alpha → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4759f1742069c140fdde13b12193676fff8a44d7
4
- data.tar.gz: b3c238ce4586e7c5201c1bb95278c6f5a62af50c
3
+ metadata.gz: 1d199ab74fcb858aa23df63831f09b1fd012f156
4
+ data.tar.gz: b3591e4c243edfaa606d1499e7ae6c461d6645d7
5
5
  SHA512:
6
- metadata.gz: a1b96656fe6f2bd535a4ce2c9bab01e8c97d318d84e81739c1cc80444cbb8fb4105cf3fc577db8b988d23f875b02ed18211124533fcf1d1f2738e3463a774a4b
7
- data.tar.gz: b6fa5d475ca7ba183044b85a02f7d26d758142e8be59ed3e6b4ce20109c2748a6f32bac3e8d5884e08935b079a497ceec325a2395b2a8402371951ac882ab534
6
+ metadata.gz: 2493a20d5551ff0224668ad13051110b55be003338598ed9050a4881f8eec8d15e8488184f3bb46c08fb4e92e7015d305fd75b8239b3ec5c8f1db36d4bc905c8
7
+ data.tar.gz: 98dbc8a3f50bb694481f2c8fe6ed30044dcbb369b488a5a995f7c6eaa27481ea01989f3ec152f32e62d3cf8f117090fde0c821a5b129385350f8ed9c8fdc2aa7
data/README.md CHANGED
@@ -1,2 +1,19 @@
1
- # download
2
- Ruby Download helper that can handle big file downloads too
1
+ # Download
2
+
3
+ Ruby Download helper that can handle even big file downloads too
4
+
5
+ ## Use case
6
+
7
+ ```ruby
8
+
9
+ require 'download'
10
+ Download.file(uri_path,target_local_file_path)
11
+
12
+ ```
13
+
14
+ ## Behavior
15
+
16
+ if the target file path is a directory, the file name will be based on the uri-s file name.
17
+ if no file path given, than the default location will be the current directory with the file uri name
18
+
19
+ The #file default return is a file path
@@ -1,5 +1,68 @@
1
- require "download/version"
1
+ require 'download/version'
2
+ require 'open-uri'
2
3
 
3
4
  module Download
4
- # Your code goes here...
5
- end
5
+
6
+ class Object
7
+
8
+ def initialize(hash={})
9
+ set_multi(hash)
10
+ raise(ArgumentError,'url is required') unless url
11
+ end
12
+
13
+ attr_accessor :url,:path
14
+
15
+ def uri_file_name
16
+ @uri_file_name ||= URI.parse(url).path.to_s.split('/').last
17
+ end
18
+
19
+ # return a string with a file path where the file will be saved
20
+ def file_path
21
+
22
+ self.path= File.join(Dir.pwd,uri_file_name) unless path
23
+ if File.directory?(path)
24
+ self.path= File.join(self.path,uri_file_name)
25
+ end
26
+
27
+ self.path
28
+
29
+ end
30
+
31
+ # start the downloading process
32
+ def start(hash={})
33
+
34
+ set_multi(hash)
35
+
36
+ File.delete(file_path) if File.exist?(file_path)
37
+ File.open(file_path,'wb') do |file_obj|
38
+ Kernel.open(url) do |fin|
39
+ while (buf = fin.read(8192))
40
+ file_obj << buf
41
+ end
42
+ end
43
+ end
44
+
45
+ return file_path
46
+
47
+ end
48
+
49
+ protected
50
+
51
+ def set_multi(hash={})
52
+ raise(ArgumentError,'input must be hash!') unless hash.is_a?(Hash)
53
+ hash.each_pair do |key,value|
54
+ self.public_send("#{key}=",value)
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ class << self
61
+
62
+ def file(file_url,target_file_path=nil)
63
+ Download::Object.new(url: file_url,path: target_file_path).start
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Download
2
- VERSION = "0.0.1.alpha"
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: download
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,9 +68,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ">"
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 1.3.1
73
+ version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
76
  rubygems_version: 2.4.3