excel_to_json 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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +30 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/excel_to_json.gemspec +39 -0
- data/exe/excel_to_json +17 -0
- data/lib/excel_to_json/version.rb +3 -0
- data/lib/excel_to_json.rb +88 -0
- data/lib/parser/base.rb +28 -0
- data/lib/parser/base_game_paytable.rb +20 -0
- data/lib/parser/base_game_strip.rb +15 -0
- data/lib/parser/free_game_paytable.rb +10 -0
- data/lib/parser/free_game_strip.rb +3 -0
- data/lib/parser/line_matrix.rb +7 -0
- data/lib/parser/symbols_parser.rb +14 -0
- data/lib/parser.rb +8 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ecc602a237cfed73c79dca0852a86ce51aa9d5e672810429f83f3ff254872f13
|
4
|
+
data.tar.gz: 84b277743e060d83f7fca3dbb4c22ebe1adc4d85209fa8c0d5b3d08dc0e5c4cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 166519e91b94aaf68dae483002f5719938f8049beb17c665c18c901624e960221cef7f5e37a796c31d8cbeafcd006b03bb2ca2a54665bab132cb90678e41723d
|
7
|
+
data.tar.gz: cacc3899ca24505a41240b12177b9ae1b8e352d4ccaf1026def1d49c97f62afee2cb11b4de9929e33b515add54529b462f655860dbc9e72795574122bc51083c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
excel_to_json (0.1.0)
|
5
|
+
highline (= 2.0.0)
|
6
|
+
roo (= 2.7.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
highline (2.0.0)
|
12
|
+
mini_portile2 (2.3.0)
|
13
|
+
nokogiri (1.8.5)
|
14
|
+
mini_portile2 (~> 2.3.0)
|
15
|
+
rake (10.5.0)
|
16
|
+
roo (2.7.1)
|
17
|
+
nokogiri (~> 1)
|
18
|
+
rubyzip (~> 1.1, < 2.0.0)
|
19
|
+
rubyzip (1.2.2)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.16)
|
26
|
+
excel_to_json!
|
27
|
+
rake (~> 10.0)
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
1.16.2
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# ExcelToJson
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/excel_to_json`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'excel_to_json'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install excel_to_json
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/excel_to_json.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "excel_to_json"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "excel_to_json/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "excel_to_json"
|
8
|
+
spec.version = ExcelToJson::VERSION
|
9
|
+
spec.authors = ["poppy"]
|
10
|
+
spec.email = ["poppy.z@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{excel file to json file}
|
13
|
+
spec.description = %q{excel file to json file}
|
14
|
+
spec.homepage = "https://gitlab.com/MofiU/excel_to_json"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
# spec.executables = %w( say_hello )
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency "roo", "2.7.1"
|
36
|
+
spec.add_dependency "highline", "2.0.0"
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
end
|
data/exe/excel_to_json
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require 'excel_to_json'
|
3
|
+
require 'highline'
|
4
|
+
|
5
|
+
cli = HighLine.new
|
6
|
+
cli.say "Welcome to use Excel To Json Tool!"
|
7
|
+
input_path = cli.ask "Please input source path,such as: sources/template.xlsx"
|
8
|
+
output_path = cli.ask "Please input output path,such as: outputs/result"
|
9
|
+
begin
|
10
|
+
ExcelToJson::Converter.new(input_path).save_as(output_path)
|
11
|
+
cli.say "Conversion successful! Output file save at #{output_path}"
|
12
|
+
rescue => err
|
13
|
+
cli.say "Error: #{err.message} !"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "excel_to_json/version"
|
2
|
+
require "parser"
|
3
|
+
require 'roo'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module ExcelToJson
|
7
|
+
class Converter
|
8
|
+
|
9
|
+
def initialize(input_file_path)
|
10
|
+
@document = load_file(input_file_path)
|
11
|
+
@supported_sheets = %w( Symbols LineMatrix BaseGamePaytable BaseGameStrip FreeGamePaytable FreeGameStrip JustTest)
|
12
|
+
@outputs = {}
|
13
|
+
raise "sheet 'Symbols' not found !" unless @document.sheets.include?('Symbols')
|
14
|
+
end
|
15
|
+
def save_as(filename)
|
16
|
+
dirname = File.dirname(filename)
|
17
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
18
|
+
|
19
|
+
File.open("#{filename}.json", 'w') do |file|
|
20
|
+
file.write(JSON.pretty_generate(serialize_json))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def to_json
|
27
|
+
@supported_sheets.each do |sheet_name|
|
28
|
+
@outputs[sheet_name.to_sym] = klass("#{sheet_name}Parser").new(@document).to_json if @document.sheets.include?(sheet_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def serialize_json
|
33
|
+
to_json
|
34
|
+
symbol_mapping = @outputs[:Symbols]
|
35
|
+
symbols = symbol_mapping.map do |_, v|
|
36
|
+
v.slice(:name, :type)
|
37
|
+
end
|
38
|
+
lines = @outputs[:LineMatrix][:lines]
|
39
|
+
|
40
|
+
paytable_mapping = ->(game_paytable) {
|
41
|
+
game_paytable[:line].each do |ele|
|
42
|
+
ele[:symbol] = symbol_mapping[ele[:symbol]][:index]
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
base_game_paytable = @outputs[:BaseGamePaytable]
|
47
|
+
free_game_paytable = @outputs[:FreeGamePaytable]
|
48
|
+
|
49
|
+
paytable_mapping.call(base_game_paytable)
|
50
|
+
paytable_mapping.call(free_game_paytable)
|
51
|
+
|
52
|
+
base_game_reels = @outputs[:BaseGameStrip][:reels]
|
53
|
+
free_game_reels = @outputs[:FreeGameStrip][:reels]
|
54
|
+
|
55
|
+
reel_mapping = ->(reels) {
|
56
|
+
reels.each do |reel|
|
57
|
+
reel.each_with_index do |ele, index|
|
58
|
+
reel[index] = symbol_mapping[ele][:index]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
}
|
62
|
+
|
63
|
+
reel_mapping.call(base_game_reels)
|
64
|
+
reel_mapping.call(free_game_reels)
|
65
|
+
|
66
|
+
{
|
67
|
+
symbols: symbols,
|
68
|
+
lines: lines,
|
69
|
+
baseGame: {
|
70
|
+
paytable: base_game_paytable,
|
71
|
+
reels: base_game_reels
|
72
|
+
},
|
73
|
+
freeGame: {
|
74
|
+
paytable: free_game_paytable,
|
75
|
+
reels: free_game_reels
|
76
|
+
}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def load_file(input_file_path)
|
81
|
+
Roo::Spreadsheet.open(input_file_path, extension: :xlsx)
|
82
|
+
end
|
83
|
+
|
84
|
+
def klass(klass_name)
|
85
|
+
Object.const_get(klass_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/parser/base.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Base
|
2
|
+
def initialize(doc)
|
3
|
+
@doc = doc
|
4
|
+
@sheet = doc.sheet(self.class.get_sheet_name)
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_json
|
8
|
+
return unless @sheet
|
9
|
+
parse_sheet
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_sheet
|
13
|
+
raise 'please define parse_sheet method'
|
14
|
+
end
|
15
|
+
|
16
|
+
def reload_sheet(sheet_name)
|
17
|
+
@sheet = @doc.sheet(sheet_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.sheet_name(sheet_name)
|
21
|
+
raise "Please define the sheet name" unless sheet_name
|
22
|
+
@sheet_name = sheet_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_sheet_name
|
26
|
+
@sheet_name
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class BaseGamePaytableParser < Base
|
2
|
+
sheet_name 'BaseGame PayTable'
|
3
|
+
|
4
|
+
def parse_sheet
|
5
|
+
line = []
|
6
|
+
(6 .. @sheet.last_row).each do |row|
|
7
|
+
reward = {}
|
8
|
+
(1 .. 5).each do |level|
|
9
|
+
multiplier = @sheet.cell(row, level + 1)
|
10
|
+
reward.merge!({ level => { multiplier: multiplier } }) if multiplier
|
11
|
+
end
|
12
|
+
symbol = @sheet.cell(row, 1)
|
13
|
+
line << {
|
14
|
+
reward: reward,
|
15
|
+
symbol: symbol
|
16
|
+
} if symbol
|
17
|
+
end
|
18
|
+
{ line: line }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class BaseGameStripParser < Base
|
2
|
+
sheet_name 'BaseGame Strip'
|
3
|
+
def parse_sheet
|
4
|
+
reels = []
|
5
|
+
(1 .. 5).each do |col|
|
6
|
+
reel = []
|
7
|
+
(3 .. @sheet.last_row).each do |row|
|
8
|
+
value = @sheet.cell(row, col)
|
9
|
+
reel.unshift(value) if value
|
10
|
+
end
|
11
|
+
reels << reel
|
12
|
+
end
|
13
|
+
{ reels: reels }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class SymbolsParser < Base
|
2
|
+
sheet_name 'Symbols'
|
3
|
+
|
4
|
+
def parse_sheet
|
5
|
+
result = @sheet.to_matrix(2, 1, nil, 3).to_a.inject({}) do |result, arr|
|
6
|
+
result[arr[1]] = {
|
7
|
+
index: arr[0],
|
8
|
+
name: arr[2],
|
9
|
+
type: arr[2].include?("WD") ? 'wild' : nil
|
10
|
+
}.compact
|
11
|
+
result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/parser.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excel_to_json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- poppy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: excel file to json file
|
70
|
+
email:
|
71
|
+
- poppy.z@outlook.com
|
72
|
+
executables:
|
73
|
+
- excel_to_json
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- excel_to_json.gemspec
|
85
|
+
- exe/excel_to_json
|
86
|
+
- lib/excel_to_json.rb
|
87
|
+
- lib/excel_to_json/version.rb
|
88
|
+
- lib/parser.rb
|
89
|
+
- lib/parser/base.rb
|
90
|
+
- lib/parser/base_game_paytable.rb
|
91
|
+
- lib/parser/base_game_strip.rb
|
92
|
+
- lib/parser/free_game_paytable.rb
|
93
|
+
- lib/parser/free_game_strip.rb
|
94
|
+
- lib/parser/line_matrix.rb
|
95
|
+
- lib/parser/symbols_parser.rb
|
96
|
+
homepage: https://gitlab.com/MofiU/excel_to_json
|
97
|
+
licenses: []
|
98
|
+
metadata:
|
99
|
+
allowed_push_host: https://rubygems.org/
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.7.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: excel file to json file
|
120
|
+
test_files: []
|