excel_to_json 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/excel_to_json.gemspec +0 -1
- data/exe/excel_to_json +2 -4
- data/lib/excel_to_json/version.rb +1 -1
- data/lib/excel_to_json.rb +11 -7
- data/lib/parser/base_game_calc_way.rb +17 -0
- data/lib/parser/base_game_paytable.rb +1 -1
- data/lib/parser/base_game_strip.rb +1 -1
- data/lib/parser/free_game_calc_way.rb +3 -0
- data/lib/parser/symbols_parser.rb +3 -3
- data/lib/parser.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 641235ca6742e1748ba45703a30738c38d1ecfeb647c55129714d2e296540dde
|
4
|
+
data.tar.gz: 8705f1128f4b837e2f1c7123df2d0ca978eb5d7674bbdc39f56d24c7a8ea8728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f22e407edb42aec0a124778c7a60a7a5eb8518fecf78fc9b2e26f21324972bbc03e470ae170b658bf10ec16b5340a3344ef8bbfeb868623c948bd1e14efca45
|
7
|
+
data.tar.gz: 1526fb7c059f028de85b63341860b2e9af821d4885896de0a2a839c02350ead550ce7f04213abc1583686aa34f9c5a4df26e840d3e39d0cfdf3e5f4b9ab46259
|
data/Gemfile.lock
CHANGED
data/excel_to_json.gemspec
CHANGED
data/exe/excel_to_json
CHANGED
@@ -6,12 +6,10 @@ cli = HighLine.new
|
|
6
6
|
cli.say "Welcome to use Excel To Json Tool!"
|
7
7
|
input_path = cli.ask "Please input source path,such as: sources/template.xlsx"
|
8
8
|
output_path = cli.ask "Please input output path,such as: outputs/result"
|
9
|
+
|
9
10
|
begin
|
10
11
|
ExcelToJson::Converter.new(input_path).save_as(output_path)
|
11
12
|
cli.say "Conversion successful! Output file save at #{output_path}"
|
12
13
|
rescue => err
|
13
14
|
cli.say "Error: #{err.message} !"
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
end
|
data/lib/excel_to_json.rb
CHANGED
@@ -8,10 +8,11 @@ module ExcelToJson
|
|
8
8
|
|
9
9
|
def initialize(input_file_path)
|
10
10
|
@document = load_file(input_file_path)
|
11
|
-
@supported_sheets = %w(
|
11
|
+
@supported_sheets = %w(Symbols BaseGameCalcWay FreeGameCalcWay LineMatrix BaseGamePaytable BaseGameStrip FreeGamePaytable FreeGameStrip )
|
12
12
|
@outputs = {}
|
13
13
|
raise "sheet 'Symbols' not found !" unless @document.sheets.include?('Symbols')
|
14
14
|
end
|
15
|
+
|
15
16
|
def save_as(filename)
|
16
17
|
dirname = File.dirname(filename)
|
17
18
|
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
@@ -25,17 +26,20 @@ module ExcelToJson
|
|
25
26
|
|
26
27
|
def to_json
|
27
28
|
@supported_sheets.each do |sheet_name|
|
28
|
-
@outputs[sheet_name.to_sym] = klass("#{sheet_name}Parser").new(@document).to_json
|
29
|
+
@outputs[sheet_name.to_sym] = klass("#{sheet_name}Parser").new(@document).to_json
|
30
|
+
rescue RangeError
|
31
|
+
next
|
29
32
|
end
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
def serialize_json
|
33
36
|
to_json
|
34
37
|
symbol_mapping = @outputs[:Symbols]
|
35
38
|
symbols = symbol_mapping.map do |_, v|
|
36
39
|
v.slice(:name, :type)
|
37
40
|
end
|
38
|
-
|
41
|
+
|
42
|
+
lines = @outputs[:LineMatrix][:lines] if @outputs[:LineMatrix]
|
39
43
|
|
40
44
|
paytable_mapping = ->(game_paytable) {
|
41
45
|
game_paytable[:line].each do |ele|
|
@@ -43,8 +47,8 @@ module ExcelToJson
|
|
43
47
|
end
|
44
48
|
}
|
45
49
|
|
46
|
-
base_game_paytable = @outputs[:BaseGamePaytable]
|
47
|
-
free_game_paytable = @outputs[:FreeGamePaytable]
|
50
|
+
base_game_paytable = @outputs[:BaseGamePaytable] || @outputs[:BaseGameCalcWay]
|
51
|
+
free_game_paytable = @outputs[:FreeGamePaytable] || @outputs[:FreeGameCalcWay]
|
48
52
|
|
49
53
|
paytable_mapping.call(base_game_paytable)
|
50
54
|
paytable_mapping.call(free_game_paytable)
|
@@ -54,7 +58,7 @@ module ExcelToJson
|
|
54
58
|
|
55
59
|
reel_mapping = ->(reels) {
|
56
60
|
reels.each do |reel|
|
57
|
-
reel.each_with_index do |ele, index|
|
61
|
+
reel.each_with_index do |ele, index|
|
58
62
|
reel[index] = symbol_mapping[ele][:index]
|
59
63
|
end
|
60
64
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class BaseGameCalcWayParser < Base
|
2
|
+
sheet_name 'Base Game Calc Ways'
|
3
|
+
|
4
|
+
def parse_sheet
|
5
|
+
res = @sheet.to_matrix(4, 1, nil, 6).to_a.select{ |line| !line[0].nil? && !line[1].nil? }.group_by{ |line| line.first.to_s.delete('~') }
|
6
|
+
line = []
|
7
|
+
res.each do |symbol, combinations|
|
8
|
+
reward = {}
|
9
|
+
combinations.inject(reward) do |reward, combination|
|
10
|
+
reward_count = combination.count { |e| e == symbol }
|
11
|
+
reward.merge!( reward_count => { multiplier: combination.last } )
|
12
|
+
end
|
13
|
+
line << { reward: reward.sort.to_h, symbol: symbol.to_s }
|
14
|
+
end
|
15
|
+
{ line: line }
|
16
|
+
end
|
17
|
+
end
|
@@ -3,10 +3,10 @@ class SymbolsParser < Base
|
|
3
3
|
|
4
4
|
def parse_sheet
|
5
5
|
result = @sheet.to_matrix(2, 1, nil, 3).to_a.inject({}) do |result, arr|
|
6
|
-
result[arr[1]] = {
|
6
|
+
result[arr[1].to_s] = {
|
7
7
|
index: arr[0],
|
8
|
-
name: arr[2],
|
9
|
-
type: arr[2].include?("WD") ? 'wild' : nil
|
8
|
+
name: arr[2].to_s,
|
9
|
+
type: arr[2].to_s.include?("WD") ? 'wild' : nil
|
10
10
|
}.compact
|
11
11
|
result
|
12
12
|
end
|
data/lib/parser.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excel_to_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poppy
|
@@ -87,8 +87,10 @@ files:
|
|
87
87
|
- lib/excel_to_json/version.rb
|
88
88
|
- lib/parser.rb
|
89
89
|
- lib/parser/base.rb
|
90
|
+
- lib/parser/base_game_calc_way.rb
|
90
91
|
- lib/parser/base_game_paytable.rb
|
91
92
|
- lib/parser/base_game_strip.rb
|
93
|
+
- lib/parser/free_game_calc_way.rb
|
92
94
|
- lib/parser/free_game_paytable.rb
|
93
95
|
- lib/parser/free_game_strip.rb
|
94
96
|
- lib/parser/line_matrix.rb
|