showdown-team-import 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/showdown-team-import +28 -13
- data/demo.webm +0 -0
- data/lib/showdown-team-import.rb +22 -6
- data/showdown-team-import.gemspec +3 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf800f0fcfa71cc66cd47a1c8a6684b6c86b670
|
4
|
+
data.tar.gz: 29fc3dd7fc9ec1a2633c5f19177175024e3bfeef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ec90b9edd14f12e6148a13f9e1b3eaa5be0df126d5eee49d97228aef0034fb9862a966db519f0bc4c061099d9743a83a74dcb275f6ac398c83ec6fa61af9e6
|
7
|
+
data.tar.gz: a06b294d98bbc122b2e305600459d141a49472e04270e49e612c81d4a8c8416ca5c3c98ddf3fa5e74737ffa4f1da7790dc0b2d2cd2e7119450aef31c827656c2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/showdown-team-import
CHANGED
@@ -2,19 +2,27 @@
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'showdown-team-import'
|
5
|
+
require 'optparse'
|
5
6
|
|
6
|
-
|
7
|
+
@options = {:silent => false,
|
8
|
+
:path => nil,
|
9
|
+
:no_dirs => false}
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage:" + " #{File.basename(__FILE__)}" + " [options] <File containing team backup>"
|
13
|
+
opts.on('-s', '--silent', 'Run silently') {@options[:silent] = true}
|
14
|
+
opts.on('-p', '--path [path]', 'Path to save to') {|v| @options[:path] = v}
|
15
|
+
opts.on( '-h', '--help', 'Display this screen' ) {puts opts; exit}
|
16
|
+
opts.on( '-n', '--no-dirs', 'Do not save in tier-specific directories (off by default)') {@options[:no_dirs] = true}
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
(puts "Input file needed. Run \"#{File.basename(__FILE__)} -h\" for more information."; exit) if ARGV.empty?
|
20
|
+
(puts "File doesn't exist. Run \"#{File.basename(__FILE__)} -h\" for more information."; exit) unless File.exists?(ARGV[0])
|
10
21
|
|
11
22
|
lines = Array.new
|
12
|
-
dir =
|
23
|
+
dir = @options[:path] || nil
|
13
24
|
|
14
|
-
|
15
|
-
raise ArgumentError, "Directory is actually file" if File.file?(dir)
|
16
|
-
FileUtils::mkdir_p dir
|
17
|
-
end
|
25
|
+
((puts "Directory is actually a file. Run \"#{File.basename(__FILE__)} -h\" for more information."; exit) if File.file?(dir)) if dir
|
18
26
|
|
19
27
|
File.foreach(ARGV[0]) do |line| # Necessary for skipping last empty line
|
20
28
|
lines << line
|
@@ -25,8 +33,8 @@ importer = TeamImporter.new
|
|
25
33
|
begin
|
26
34
|
importer.import(lines)
|
27
35
|
rescue ParserError => e
|
28
|
-
puts e.message
|
29
|
-
puts e.line
|
36
|
+
puts "An error has occurred: " + e.message
|
37
|
+
puts "The error occurred at the following line: " + e.line
|
30
38
|
end
|
31
39
|
|
32
40
|
teams = importer.teams
|
@@ -34,13 +42,20 @@ teams = importer.teams
|
|
34
42
|
teams.each do |team| # actual file writing
|
35
43
|
team_content = team.content.gsub(/\n{3,}/, "\n") # replace 3 or more newlines with a single one
|
36
44
|
filename = team.name.delete("/").strip + ".team" # ruby mistakes / for path separator
|
37
|
-
|
38
|
-
|
45
|
+
filename = File.join(team.tier, filename) unless @options[:no_dirs] # add tier-specific path
|
46
|
+
|
47
|
+
if dir
|
48
|
+
unless @options[:no_dirs]
|
49
|
+
FileUtils::mkdir_p File.join(dir, team.tier)
|
50
|
+
else
|
51
|
+
FileUtils::mkdir_p dir
|
52
|
+
end
|
39
53
|
location = File.join(dir, filename) # saving in specified directory
|
40
54
|
else
|
55
|
+
FileUtils::mkdir_p team.tier unless @options[:no_dirs]
|
41
56
|
location = filename # saving in current directory
|
42
57
|
end
|
43
58
|
|
44
|
-
puts "Writing \"#{location}\""
|
59
|
+
puts "Writing \"#{location}\"" unless @options[:silent]
|
45
60
|
File.write(location, team_content)
|
46
61
|
end
|
data/demo.webm
ADDED
Binary file
|
data/lib/showdown-team-import.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Classes related to team parsing are defined here.
|
2
2
|
|
3
|
-
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
Team = Struct.new(:name, :tier, :content)
|
4
6
|
|
5
7
|
class ParserError < StandardError
|
6
8
|
attr_reader :line
|
@@ -17,20 +19,20 @@ class TeamImporter
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def import team_import
|
20
|
-
team = Team.new(String.new, String.new)
|
22
|
+
team = Team.new(String.new, String.new, String.new)
|
21
23
|
line_count = 0
|
22
24
|
in_team = false
|
23
25
|
|
24
26
|
team_import.each do |line, count|
|
25
27
|
next if line.equal? team_import.last # I haven't found any way to make this not an error except adding more shitty checks
|
26
28
|
if in_team
|
27
|
-
team.content += line unless team.content.
|
29
|
+
team.content += line unless team.content.empty? && line.strip.empty? # Beginning of file
|
28
30
|
|
29
31
|
if line.strip == ''
|
30
32
|
line_count += 1
|
31
33
|
if line_count == 2 # 2 empty lines = end of current team
|
32
34
|
@teams.push(team) # add team to array and reset everything
|
33
|
-
team = Team.new(String.new, String.new)
|
35
|
+
team = Team.new(String.new, String.new, String.new)
|
34
36
|
in_team = false
|
35
37
|
line_count = 0
|
36
38
|
end
|
@@ -39,9 +41,23 @@ class TeamImporter
|
|
39
41
|
end
|
40
42
|
elsif line[0..2] == "===" && line.chomp.reverse[0..2] == "===" # beginning of team
|
41
43
|
in_team = true
|
42
|
-
|
44
|
+
name_and_tier = line[4..-5]
|
45
|
+
bracket_index = name_and_tier.index(']') # 10/10 code I know
|
46
|
+
format = name_and_tier[1..bracket_index-1] if !bracket_index.nil? && bracket_index > 2
|
47
|
+
format = "others" unless format
|
48
|
+
|
49
|
+
if !bracket_index.nil? && !name_and_tier[bracket_index + 1..-1].strip.empty?
|
50
|
+
team_name = name_and_tier[bracket_index + 1..-1]
|
51
|
+
elsif !name_and_tier.strip.empty? && bracket_index.nil?
|
52
|
+
team_name = name_and_tier
|
53
|
+
else
|
54
|
+
team_name = "Untitled [#{SecureRandom.hex[0..5]}]"
|
55
|
+
end
|
56
|
+
|
57
|
+
team.name = team_name
|
58
|
+
team.tier = format
|
43
59
|
else
|
44
|
-
raise ParserError(line), "Error parsing backup file"
|
60
|
+
raise ParserError.new(line), "Error parsing backup file"
|
45
61
|
end
|
46
62
|
end
|
47
63
|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: showdown-team-import 0.
|
5
|
+
# stub: showdown-team-import 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "showdown-team-import"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"bin/showdown-team-import",
|
31
|
+
"demo.webm",
|
31
32
|
"lib/showdown-team-import.rb",
|
32
33
|
"showdown-team-import.gemspec"
|
33
34
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: showdown-team-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- apt-get
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- Rakefile
|
72
72
|
- VERSION
|
73
73
|
- bin/showdown-team-import
|
74
|
+
- demo.webm
|
74
75
|
- lib/showdown-team-import.rb
|
75
76
|
- showdown-team-import.gemspec
|
76
77
|
homepage: http://github.com/lc-guy/showdown-team-import
|