simple-images-downloader 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ class Line
5
+ def initialize(string)
6
+ @string = string
7
+ end
8
+
9
+ def uri
10
+ parsed_uri = URI.parse(@string)
11
+
12
+ ImagePathValidator.new(@string).validate
13
+
14
+ parsed_uri
15
+ rescue URI::Error
16
+ raise Errors::BadUrl, @string
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ class Runner
5
+ def self.invoke
6
+ raise SimpleImagesDownloader::Errors::MissingFileArgumentError if ARGV.size.zero?
7
+
8
+ SimpleImagesDownloader.from_file(ARGV.first)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ class SourceFile
5
+ def initialize(path, validator = nil)
6
+ @path = path
7
+ @validator = validator || SimpleImagesDownloader::FilePersistanceValidator.new(path)
8
+ end
9
+
10
+ def each_line(&block)
11
+ @validator.validate
12
+
13
+ begin
14
+ file.each(chomp: true, &block)
15
+ ensure
16
+ file.close
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def file
23
+ @file ||= File.open(@path, 'r')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module StringioToTempfile
5
+ module_function
6
+
7
+ def convert(stringio)
8
+ tempfile = Tempfile.new(binmode: true)
9
+
10
+ IO.copy_stream(stringio, tempfile)
11
+
12
+ stringio.close
13
+
14
+ OpenURI::Meta.init tempfile, stringio
15
+
16
+ tempfile
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,82 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-faker
4
+
5
+ AllCops:
6
+ UseCache: true
7
+ MaxFilesInCache: 5
8
+ NewCops: enable
9
+ CacheRootDirectory: ./tmp/**
10
+ TargetRubyVersion: 2.7.1
11
+ DisplayCopNames: true
12
+ Exclude:
13
+ - bin/**/*
14
+ - tmp/**/*
15
+ - vendor/**/*
16
+
17
+ RSpec/MultipleExpectations:
18
+ Enabled: false
19
+
20
+ RSpec/ExampleLength:
21
+ Enabled: false
22
+
23
+ RSpec/RepeatedDescription:
24
+ Enabled: false
25
+
26
+ RSpec/MessageSpies:
27
+ EnforcedStyle: receive
28
+
29
+ Style/AndOr:
30
+ Enabled: false
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Style/MethodCalledOnDoEndBlock:
36
+ Enabled: true
37
+
38
+ Style/CollectionMethods:
39
+ Enabled: true
40
+
41
+ Style/SymbolArray:
42
+ Enabled: true
43
+
44
+ Style/StringLiterals:
45
+ EnforcedStyle: single_quotes
46
+ ConsistentQuotesInMultiline: true
47
+
48
+ Style/EmptyMethod:
49
+ EnforcedStyle: expanded
50
+ SupportedStyles:
51
+ - compact
52
+ - expanded
53
+
54
+ Layout/ParameterAlignment:
55
+ EnforcedStyle: with_fixed_indentation
56
+ SupportedStyles:
57
+ - with_first_parameter
58
+ - with_fixed_indentation
59
+
60
+ Style/FrozenStringLiteralComment:
61
+ Enabled: true
62
+
63
+ Style/StringMethods:
64
+ Enabled: true
65
+
66
+ Layout/LineLength:
67
+ Max: 120
68
+
69
+ Metrics/BlockLength:
70
+ Enabled: false
71
+
72
+ Layout/EndAlignment:
73
+ EnforcedStyleAlignWith: variable
74
+ SupportedStylesAlignWith:
75
+ - keyword
76
+ - variable
77
+
78
+ Naming/VariableNumber:
79
+ EnforcedStyle: snake_case
80
+
81
+ RSpec/NestedGroups:
82
+ Max: 4
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require_relative 'lib/simple_images_downloader/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'simple-images-downloader'
10
+ spec.version = SimpleImagesDownloader::VERSION
11
+ spec.authors = ['IlkhamGaysin']
12
+ spec.email = ['ilgamgaysin@gmail.com']
13
+
14
+ spec.summary = 'simple-images-downloader allows to download images' \
15
+ ' from a file containing list of urls to those images.'
16
+ spec.homepage = 'https://github.com/IlkhamGaysin/simple-images-downloader'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.1')
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/IlkhamGaysin/simple-images-downloader'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/IlkhamGaysin/simple-images-downloader/blob/master/CHANGELOG.md'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler-audit'
34
+ spec.add_development_dependency 'faker'
35
+ spec.add_development_dependency 'memory_profiler'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'pry-byebug'
38
+ spec.add_development_dependency 'rake', '~> 12.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rspec_junit_formatter'
41
+ spec.add_development_dependency 'rubocop'
42
+ spec.add_development_dependency 'rubocop-faker'
43
+ spec.add_development_dependency 'rubocop-rspec'
44
+ spec.add_development_dependency 'simplecov', '~> 0.17.1'
45
+ spec.add_development_dependency 'vcr'
46
+ spec.add_development_dependency 'webmock'
47
+ spec.add_runtime_dependency 'zeitwerk'
48
+ end
metadata ADDED
@@ -0,0 +1,291 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-images-downloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - IlkhamGaysin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler-audit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: memory_profiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec_junit_formatter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-faker
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.17.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.17.1
181
+ - !ruby/object:Gem::Dependency
182
+ name: vcr
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: webmock
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: zeitwerk
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description:
224
+ email:
225
+ - ilgamgaysin@gmail.com
226
+ executables:
227
+ - simple-images-downloader
228
+ extensions: []
229
+ extra_rdoc_files: []
230
+ files:
231
+ - ".circleci/config.yml"
232
+ - ".codeclimate.yml"
233
+ - ".gitignore"
234
+ - ".rspec"
235
+ - ".ruby-version"
236
+ - CHANGELOG.md
237
+ - CODE_OF_CONDUCT.md
238
+ - Gemfile
239
+ - Gemfile.lock
240
+ - LICENSE.txt
241
+ - README.md
242
+ - Rakefile
243
+ - bin/bundle
244
+ - bin/console
245
+ - bin/quality
246
+ - bin/rspec
247
+ - bin/rubocop
248
+ - bin/setup
249
+ - exe/simple-images-downloader
250
+ - lib/simple_images_downloader.rb
251
+ - lib/simple_images_downloader/configuration.rb
252
+ - lib/simple_images_downloader/dispenser.rb
253
+ - lib/simple_images_downloader/downloader.rb
254
+ - lib/simple_images_downloader/errors.rb
255
+ - lib/simple_images_downloader/file_persistance_validator.rb
256
+ - lib/simple_images_downloader/image_path_validator.rb
257
+ - lib/simple_images_downloader/line.rb
258
+ - lib/simple_images_downloader/runner.rb
259
+ - lib/simple_images_downloader/source_file.rb
260
+ - lib/simple_images_downloader/stringio_to_tempfile.rb
261
+ - lib/simple_images_downloader/version.rb
262
+ - rubocop.yml
263
+ - simple_images_downloader.gemspec
264
+ homepage: https://github.com/IlkhamGaysin/simple-images-downloader
265
+ licenses:
266
+ - MIT
267
+ metadata:
268
+ homepage_uri: https://github.com/IlkhamGaysin/simple-images-downloader
269
+ source_code_uri: https://github.com/IlkhamGaysin/simple-images-downloader
270
+ changelog_uri: https://github.com/IlkhamGaysin/simple-images-downloader/blob/master/CHANGELOG.md
271
+ post_install_message:
272
+ rdoc_options: []
273
+ require_paths:
274
+ - lib
275
+ required_ruby_version: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - ">="
278
+ - !ruby/object:Gem::Version
279
+ version: 2.7.1
280
+ required_rubygems_version: !ruby/object:Gem::Requirement
281
+ requirements:
282
+ - - ">="
283
+ - !ruby/object:Gem::Version
284
+ version: '0'
285
+ requirements: []
286
+ rubygems_version: 3.1.2
287
+ signing_key:
288
+ specification_version: 4
289
+ summary: simple-images-downloader allows to download images from a file containing
290
+ list of urls to those images.
291
+ test_files: []