gs_img_fetcher 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: a9349da7d358fea7bb7ae7bb75472a396cd6810e3348f1ce09ad199a5e47ad7e
4
- data.tar.gz: eeb7ef868ad8f4f7c1dbc5a260880a83c8fd1baca676b1994d05546af5751fe7
3
+ metadata.gz: b3ce17816770496a81e56ee290c9eda21bacddfb0e81c3fbce712ae50d477b64
4
+ data.tar.gz: e239f232dddbb0c201633837a0d680c245813b26420d0e316b0bf7baaeaec1de
5
5
  SHA512:
6
- metadata.gz: 74dd2fe6d6d39ed3fb9f485c163d28121fcef11baa708d8ed2e0f713ed39d310efdd2db725e468ea7440e8615cad175bc52a20d31cdd60e17d954d06489f4cc1
7
- data.tar.gz: 1376fb3f38b62c1cf2e336efa6596af1d29b861368a6ae185a18b706e52cc7e1606b3649d9f04c75d8cb650f5e8bcb08c46c5d1dfd9ffed63967f06e3b7f3838
6
+ metadata.gz: 732e6099d8c80fc0bad6bb891acdcaa77b262d717944b33e0ab8aaa699802312138765e6a278afa66af44653bb8e1ff5669c0198a15eda3976faf14fc8c38a68
7
+ data.tar.gz: 905ea2430a1aeca45d2d07ffd71ffeeaa9937381dde32e0a32213c756825057fcbaf31d0942f2f1003e11154d82c3bf815305c7618bb3ecf803da6563225c79b
data/README.md CHANGED
@@ -53,7 +53,7 @@ Set the environment variable `NOLOG` to a truthy value to suppress logs.
53
53
  #### Fetching a single image
54
54
  ```ruby
55
55
  fetcher = GsImgFetcher::Fetcher.new(
56
- GsImgFetcher::InputEntry.new('http://example.com/image.png'),
56
+ GsImgFetcher::Entry.new('http://example.com/image.png'),
57
57
  'output'
58
58
  )
59
59
  fetcher.fetch
@@ -63,18 +63,18 @@ fetcher.successful?
63
63
 
64
64
  #### Fetching multiple images
65
65
  ```ruby
66
- input = GsImgFetcher::Input.from_file('urls.txt')
66
+ entry_set = GsImgFetcher::EntrySet.from_file('urls.txt')
67
67
  # or
68
68
  urls = ['http://example.com/image.png', 'http://example.com/image2.png']
69
- entries = urls.map { |url| GsImgFetcher::InputEntry.new(url) }
70
- input = GsImgFetcher::Input.new (entries)
69
+ entries = urls.map { |url| GsImgFetcher::Entry.new(url) }
70
+ entry_set = GsImgFetcher::EntrySet.new(entries)
71
71
 
72
- manager = GsImgFetcher::Manager.new(input, output_dir: 'output', async: false)
72
+ manager = GsImgFetcher::Manager.new(entry_set, output_dir: 'output', async: false)
73
73
  manager.setup.fetch
74
74
  ```
75
75
 
76
76
  - `Manager` is what controls the entire process of handling the input and fetching and saving the images.
77
- - `Input` is responsible for finding the input file and parsing, sanitizing and validating the list of URLs.
77
+ - `EntrySet` is responsible for finding the input file and parsing, sanitizing and validating the list of URLs.
78
78
  - `Fetcher` is responsible for downloading and saving images.
79
79
 
80
80
  ## Development
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GsImgFetcher
4
- class InputEntry
4
+ class Entry
5
5
  ALLOWED_EXTENSIONS = %w[jpeg jpg png gif svg].freeze
6
6
 
7
7
  attr_reader :url
@@ -3,13 +3,13 @@
3
3
  require 'active_support/core_ext/object/blank'
4
4
 
5
5
  module GsImgFetcher
6
- class Input
6
+ class EntrySet
7
7
  class << self
8
8
  def from_file(path)
9
9
  entries = File.open(path, 'r') { |f| f.each_line.map(&:strip).map(&:presence) }
10
10
  .compact
11
11
  .uniq
12
- .map { |url| InputEntry.new(url) }
12
+ .map { |url| Entry.new(url) }
13
13
  new(entries)
14
14
  end
15
15
  end
@@ -6,17 +6,17 @@ module GsImgFetcher
6
6
  class Manager
7
7
  class << self
8
8
  def fetch(input_path, **opts)
9
- input = Input.from_file(input_path)
10
- new(input, **opts).setup.fetch
9
+ entry_set = EntrySet.from_file(input_path)
10
+ new(entry_set, **opts).setup.fetch
11
11
  end
12
12
  end
13
13
 
14
- attr_reader :input, :entries, :successful_fetches, :failed_fetches
14
+ attr_reader :entry_set, :entries, :successful_fetches, :failed_fetches
15
15
 
16
16
  DEFAULT_MAX_THREADS = Concurrent.processor_count
17
17
 
18
- def initialize(input, output_dir: nil, async: true, max_threads: nil)
19
- @input = input
18
+ def initialize(entry_set, output_dir: nil, async: true, max_threads: nil)
19
+ @entry_set = entry_set
20
20
  @output_dir = output_dir || Dir.pwd
21
21
  @async = async
22
22
  @max_threads = max_threads || DEFAULT_MAX_THREADS
@@ -31,7 +31,7 @@ module GsImgFetcher
31
31
 
32
32
  next unless entries.empty?
33
33
 
34
- input.valid_entries.each { |e| entries.push(e) }
34
+ entry_set.valid_entries.each { |e| entries.push(e) }
35
35
  end
36
36
  end
37
37
 
@@ -78,7 +78,7 @@ module GsImgFetcher
78
78
  end
79
79
 
80
80
  def log_entries
81
- LOGGER.info("Processing #{input.entries.count} URLs (#{input.valid_entries.count} valid, #{input.invalid_entries.count} invalid)")
81
+ LOGGER.info("Processing #{entry_set.entries.count} URLs (#{entry_set.valid_entries.count} valid, #{entry_set.invalid_entries.count} invalid)")
82
82
  end
83
83
 
84
84
  def log_result
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GsImgFetcher
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -3,8 +3,8 @@
3
3
  require 'logger'
4
4
  require 'gs_img_fetcher/version'
5
5
  require 'gs_img_fetcher/fetcher'
6
- require 'gs_img_fetcher/input_entry'
7
- require 'gs_img_fetcher/input'
6
+ require 'gs_img_fetcher/entry'
7
+ require 'gs_img_fetcher/entry_set'
8
8
  require 'gs_img_fetcher/manager'
9
9
 
10
10
  module GsImgFetcher
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gs_img_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiko Ito
@@ -187,9 +187,9 @@ files:
187
187
  - exe/gs_img_fetcher
188
188
  - gs_img_fetcher.gemspec
189
189
  - lib/gs_img_fetcher.rb
190
+ - lib/gs_img_fetcher/entry.rb
191
+ - lib/gs_img_fetcher/entry_set.rb
190
192
  - lib/gs_img_fetcher/fetcher.rb
191
- - lib/gs_img_fetcher/input.rb
192
- - lib/gs_img_fetcher/input_entry.rb
193
193
  - lib/gs_img_fetcher/manager.rb
194
194
  - lib/gs_img_fetcher/version.rb
195
195
  homepage: https://github.com/AkihikoITOH/gs_img_fetcher