parker 0.2.0 → 0.2.1

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: e6b3d51c383bb6974823917dd10513689ac3797a
4
- data.tar.gz: 78dcc1a3f3f3500856b0f8926161d78c57b7c211
3
+ metadata.gz: a6140e492f8266e3ee41d4469b399277ea94b69c
4
+ data.tar.gz: fcf9872e68727c46c18664a41b1c07ff2c3b7c42
5
5
  SHA512:
6
- metadata.gz: d49768e3885a97d26f79e9df40502b7f1119956668baf4707054f9451ba5d2f1c69e88de5048f1c933a88d1d48c95601966e2f99f49a1cb7f682417b806f844e
7
- data.tar.gz: 02ab2d5533de7a4a170bc91a1ac88390ba914dc01b6314bb8a25eb940f92c03dfd2c5b644f69c280f4812737b57354fe05fe6f31f8827cbc407fb99f26a83c22
6
+ metadata.gz: d3e9f6940aa89ccee818dbca691bda029c2ab9446937412c8587aa32c918531466a49ad49f32acf4771e46f2cfa57f7d60231a096421873242217ad002470e23
7
+ data.tar.gz: bd32a4526d1d5ed7ffe5a7c5f3fc762f20b89e8785cad04a62e89904f79e9e69105ef7a1202b3fa7848bcaadcf2b59392f7ba55e9beb320194d8a9d18b3e638e
data/bin/parker CHANGED
@@ -15,15 +15,15 @@ end
15
15
 
16
16
  source_directory = File.expand_path(File.join('~/', '.config', 'parker'))
17
17
 
18
- options = Trollop.options do
18
+ Trollop.options do
19
19
  version "parker v#{Parker::VERSION}"
20
- banner <<-EOS
20
+ banner <<-BANNER
21
21
  A ridiculous tool for organising game screenshots.
22
22
 
23
23
  Usage:
24
24
  parker [output directory]
25
25
  Options:
26
- EOS
26
+ BANNER
27
27
  end
28
28
 
29
29
  unless Dir.exist?(source_directory)
@@ -58,30 +58,30 @@ Dir.glob(File.join(source_directory, 'platforms', '*.json')).each do |path|
58
58
  end
59
59
 
60
60
  if platforms.empty?
61
- puts "Nothing to do (no platforms found)."
61
+ puts 'Nothing to do (no platforms found).'
62
62
  exit
63
63
  end
64
64
 
65
65
  output_path = File.expand_path(ARGV[0])
66
66
  FileUtils.mkdir_p(output_path) unless Dir.exist?(output_path)
67
67
 
68
- puts "Scanning..."
68
+ puts 'Scanning...'
69
69
 
70
70
  platforms.each do |platform|
71
71
  platform.games.each_value do |game|
72
- if game.screenshots.length > 0
73
- print "- #{game.name} (#{platform.name}): "
72
+ next unless game.screenshots.count.positive?
74
73
 
75
- platform_path = File.join(output_path, platform.name)
76
- copied_count = game.copy_screenshots(platform_path)
74
+ print "- #{game.name} (#{platform.name}): "
77
75
 
78
- if copied_count > 0
79
- puts "Copied #{copied_count} new screenshot#{'s' unless copied_count == 1}."
80
- else
81
- puts '✓'
82
- end
76
+ platform_path = File.join(output_path, platform.name)
77
+ copied_count = game.copy_screenshots(platform_path)
78
+
79
+ if copied_count.positive?
80
+ puts "Copied #{copied_count} new screenshot#{'s' if copied_count != 1}."
81
+ else
82
+ puts '✓'
83
83
  end
84
84
  end
85
85
  end
86
86
 
87
- puts "\nDone!"
87
+ puts "\nDone!"
@@ -11,4 +11,4 @@ require 'parker/screenshot'
11
11
  require 'parker/platform/base'
12
12
  require 'parker/platform/ps4'
13
13
  require 'parker/platform/steam'
14
- require 'parker/platform/switch'
14
+ require 'parker/platform/switch'
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parker
4
+ # A class that models a single game.
2
5
  class Game
3
6
  attr_accessor :identifier, :name, :screenshots
4
7
 
@@ -26,4 +29,4 @@ module Parker
26
29
  copied_screenshots
27
30
  end
28
31
  end
29
- end
32
+ end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parker
2
4
  module Platform
5
+ # A base class for all platforms.
3
6
  class Base
4
7
  attr_reader :name, :source_path
5
8
  attr_accessor :games
@@ -9,13 +12,11 @@ module Parker
9
12
  @source_path = source_path
10
13
  @games = {}
11
14
 
12
- unless game_data.nil?
13
- game_data.map do |identifier, name|
14
- @games[identifier] = Game.new(identifier, name)
15
- end
15
+ game_data&.map do |game_identifier, game_name|
16
+ @games[game_identifier] = Game.new(game_identifier, game_name)
16
17
  end
17
18
 
18
- scan_games
19
+ scan_games if Dir.exist?(@source_path)
19
20
  end
20
21
 
21
22
  def scan_games
@@ -23,4 +24,4 @@ module Parker
23
24
  end
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -1,21 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest'
2
4
 
3
5
  module Parker
4
6
  module Platform
7
+ # A class that models the PlayStation 4 platform.
5
8
  class PS4 < Base
6
9
  def scan_games
7
10
  screenshots_path = File.join(source_path, '*', File::SEPARATOR, '*.jpg')
8
11
 
9
12
  Dir.glob(screenshots_path).each do |path|
10
- next if (path =~ /\_\d.jpg$/)
13
+ next if path.match?(/\_\d.jpg$/)
11
14
 
12
- (game_name, screenshot_date) = File.basename(path, File.extname(path)).split('_')
15
+ game_name = File.basename(path, File.extname(path)).split('_')[0]
13
16
  game_id = Digest::SHA1.hexdigest(game_name)[0..9]
14
17
 
15
- games[game_id] ||= Game.new(game_name.sub('™', '').sub('_', ' -'))
18
+ games[game_id] ||= Game.new(game_id, game_name.sub('™', '').sub('_', ' -'))
16
19
  games[game_id].screenshots << Screenshot.new(path)
17
20
  end
18
21
  end
19
22
  end
20
23
  end
21
- end
24
+ end
@@ -1,9 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parker
2
4
  module Platform
5
+ # A class that models the Steam platform.
3
6
  class Steam < Base
4
7
  def scan_games
5
8
  games.each do |identifier, game|
6
- screenshot_path = File.join(source_path, identifier.to_s, 'screenshots', '*.jpg')
9
+ screenshot_path = File.join(
10
+ source_path,
11
+ identifier.to_s,
12
+ 'screenshots',
13
+ '*.jpg'
14
+ )
7
15
 
8
16
  Dir.glob(screenshot_path).each do |path|
9
17
  game.screenshots << Screenshot.new(path)
@@ -12,4 +20,4 @@ module Parker
12
20
  end
13
21
  end
14
22
  end
15
- end
23
+ end
@@ -1,14 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parker
2
4
  module Platform
5
+ # A class that models the Nintendo Switch platform.
3
6
  class Switch < Base
4
7
  def scan_games
5
8
  screenshot_path = File.join(source_path, '**', '*.jpg')
6
9
 
7
10
  Dir.glob(screenshot_path).each do |path|
8
11
  game_id = File.basename(path, File.extname(path)).split('-')[-1]
9
- games[game_id].screenshots << Screenshot.new(path) if games[game_id]
12
+ (games[game_id].screenshots ||= {}) << Screenshot.new(path)
10
13
  end
11
14
  end
12
15
  end
13
16
  end
14
- end
17
+ end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Parker
4
+ # A class that models a single game screenshot.
2
5
  class Screenshot
3
6
  attr_reader :path
4
7
  attr_accessor :filename
@@ -6,8 +9,10 @@ module Parker
6
9
  def initialize(path)
7
10
  @path = path
8
11
 
9
- parts = File.basename(@path).match(/(\d{4})(\d{2})(\d{2})(\d+).+(\.[a-z]{3})/)
12
+ name_pattern = /(\d{4})(\d{2})(\d{2})(\d+).+(\.[a-z]{3})/
13
+ parts = File.basename(@path).match(name_pattern)
14
+
10
15
  @filename = parts.to_a[1..-2].join('-') << parts[-1]
11
16
  end
12
17
  end
13
- end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parker
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-05 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop