showdown-team-import 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c7286f1e7abbe22601333b088e9ec9628945110
4
+ data.tar.gz: 8fb825b886cbec5f7e8f256ba47a0a8bf1b78b34
5
+ SHA512:
6
+ metadata.gz: 8d96bbed3a5571d7bf21f7f526dd85e3d25880003c29e6adf69bab07536c10dc4df704ce313a36a194031af70cecf215d5ca016315fa7a7caf2006e69b8bee9d
7
+ data.tar.gz: 84770ea9563727200c07def49811a7ead33b3ca3cf44c940a5f0b463e0732dbf665ff229b477ccdbc4408d3deda6a4cd1e27e4afe840497c1a26135cc84b27cd
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.0"
11
+ gem "jeweler", "~> 2.0.1"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.8)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ faraday (0.9.1)
9
+ multipart-post (>= 1.2, < 3)
10
+ git (1.2.9.1)
11
+ github_api (0.12.4)
12
+ addressable (~> 2.3)
13
+ descendants_tracker (~> 0.0.4)
14
+ faraday (~> 0.8, < 0.10)
15
+ hashie (>= 3.4)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ nokogiri (~> 1.6.6)
18
+ oauth2
19
+ hashie (3.4.2)
20
+ highline (1.7.3)
21
+ jeweler (2.0.1)
22
+ builder
23
+ bundler (>= 1.0)
24
+ git (>= 1.2.5)
25
+ github_api
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ rake
29
+ rdoc
30
+ json (1.8.3)
31
+ jwt (1.5.1)
32
+ mini_portile (0.6.2)
33
+ multi_json (1.11.2)
34
+ multi_xml (0.5.5)
35
+ multipart-post (2.0.0)
36
+ nokogiri (1.6.6.2)
37
+ mini_portile (~> 0.6.0)
38
+ oauth2 (1.0.0)
39
+ faraday (>= 0.8, < 0.10)
40
+ jwt (~> 1.0)
41
+ multi_json (~> 1.3)
42
+ multi_xml (~> 0.5)
43
+ rack (~> 1.2)
44
+ rack (1.6.4)
45
+ rake (10.4.2)
46
+ rdoc (3.12.2)
47
+ json (~> 1.4)
48
+ thread_safe (0.3.5)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 1.0)
55
+ jeweler (~> 2.0.1)
56
+ rdoc (~> 3.12)
57
+
58
+ BUNDLED WITH
59
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 apt-get
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = showdown-team-import
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to showdown-team-import
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2015 apt-get. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "showdown-team-import"
18
+ gem.homepage = "http://github.com/lc-guy/showdown-team-import"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Pokemon Showdown! team backup parser that lets you export to files.}
21
+ gem.description = %Q{A basic ruby gem which takes a team backup file and an optional directory as arguments,} +
22
+ %Q{and writes each team as a separate file inside the specified directory (or in the current directory).}
23
+ gem.email = "aptyget@gmail.com"
24
+ gem.authors = ["apt-get"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rdoc/task'
30
+ Rake::RDocTask.new do |rdoc|
31
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
32
+
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = "showdown-team-import #{version}"
35
+ rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'showdown-team-import'
5
+
6
+ (puts "Usage: #{File.basename(__FILE__)} <file containing teams> [optional directory]"; exit) if ARGV.empty?
7
+
8
+ raise ArgumentError, "No file provided" if ARGV[0].nil?
9
+ raise ArgumentError, "File doesn't exist" unless File.exists?(ARGV[0])
10
+
11
+ lines = Array.new
12
+ dir = ARGV[1] || false
13
+
14
+ unless dir == false
15
+ raise ArgumentError, "Directory is actually file" if File.file?(dir)
16
+ FileUtils::mkdir_p dir
17
+ end
18
+
19
+ File.foreach(ARGV[0]) do |line| # Necessary for skipping last empty line
20
+ lines << line
21
+ end
22
+
23
+ importer = TeamImporter.new
24
+
25
+ begin
26
+ importer.import(lines)
27
+ rescue ParserError => e
28
+ puts e.message
29
+ puts e.line
30
+ end
31
+
32
+ teams = importer.teams
33
+
34
+ teams.each do |team| # actual file writing
35
+ team_content = team.content.gsub(/\n{3,}/, "\n") # replace 3 or more newlines with a single one
36
+ filename = team.name.delete("/").strip + ".team" # ruby mistakes / for path separator
37
+
38
+ unless dir == false
39
+ location = File.join(dir, filename) # saving in specified directory
40
+ else
41
+ location = filename # saving in current directory
42
+ end
43
+
44
+ puts "Writing \"#{location}\""
45
+ File.write(location, team_content)
46
+ end
@@ -0,0 +1,50 @@
1
+ # Classes related to team parsing are defined here.
2
+
3
+ Team = Struct.new(:name, :content)
4
+
5
+ class ParserError < StandardError
6
+ attr_reader :line
7
+ def initialize(line)
8
+ @line = line
9
+ end
10
+ end
11
+
12
+ class TeamImporter
13
+ attr_reader :teams
14
+
15
+ def initialize
16
+ @teams = Array.new
17
+ end
18
+
19
+ def import team_import
20
+ team = Team.new(String.new, String.new)
21
+ line_count = 0
22
+ in_team = false
23
+
24
+ team_import.each do |line, count|
25
+ 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
+ if in_team
27
+ team.content += line unless team.content.nil? && line.strip.empty? # Beginning of file
28
+
29
+ if line.strip == ''
30
+ line_count += 1
31
+ if line_count == 2 # 2 empty lines = end of current team
32
+ @teams.push(team) # add team to array and reset everything
33
+ team = Team.new(String.new, String.new)
34
+ in_team = false
35
+ line_count = 0
36
+ end
37
+ else # we already appended line earlier, so just resetting linecount
38
+ line_count = 0
39
+ end
40
+ elsif line[0..2] == "===" && line.chomp.reverse[0..2] == "===" # beginning of team
41
+ in_team = true
42
+ team.name = line[4..-5] # remove identifiers
43
+ else
44
+ raise ParserError(line), "Error parsing backup file"
45
+ end
46
+ end
47
+
48
+ @teams.push(team) if @teams.empty?
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: showdown-team-import
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - apt-get
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.1
55
+ description: A basic ruby gem which takes a team backup file and an optional directory
56
+ as arguments,and writes each team as a separate file inside the specified directory
57
+ (or in the current directory).
58
+ email: aptyget@gmail.com
59
+ executables:
60
+ - showdown-team-import
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - LICENSE.txt
64
+ - README.rdoc
65
+ files:
66
+ - ".document"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.rdoc
71
+ - Rakefile
72
+ - VERSION
73
+ - bin/showdown-team-import
74
+ - lib/showdown-team-import.rb
75
+ homepage: http://github.com/lc-guy/showdown-team-import
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A Pokemon Showdown! team backup parser that lets you export to files.
99
+ test_files: []