rggen-spreadsheet-loader 0.16.0 → 0.17.0

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
  SHA256:
3
- metadata.gz: bf9a2598faafa52f60ab349dbf8a3f8abd62bb1ce4c4a9bb146c3161194c5a0c
4
- data.tar.gz: 4c733349b76ec9c4641cb6a30c5b955a9e8551463d53806011d0af6cb3de0605
3
+ metadata.gz: 1a5c038c878bdee2d0369695504d66c0773c5778ca6ba27ad20960c525f0ef32
4
+ data.tar.gz: 698efcc2c97a0603b7212e35eef134a1526485bd77383bfc27a490f44a21eb87
5
5
  SHA512:
6
- metadata.gz: 7abd9a096f7df1f5497daa44e917c3bc7542a0885034ebffcee415eda8b960b2b81484879cf323d2fac9beb65713d2b41536d309d51090eec7ffc6278dae2a94
7
- data.tar.gz: '09b4010e88e75ea6c49c1527e9338f04ba1a0600665ffc2b8116f41fa92efaba1211ea6a2c9260750c471d507e8bea47bc4b832f133f3f21d32ec8153cf269c8'
6
+ metadata.gz: 8df01bd76a566ccbbdbcd4e8efab23f20d3f7f64d8908d0cd7bbdcd6c0fe8f4aa1f4ffa1d6cc935d9843f5efaf813275e6af1f9141d188c607a19dc18490c81a
7
+ data.tar.gz: c806612b266d7a64e432490f96c5c9468e9d3739ae286728402e60822e82ce1b3f5cfcba4ec73d07c05b3e07490ccb49678a73c5fde86295b5f83576e4612f08
@@ -14,9 +14,9 @@ require_relative 'spreadsheet_loader/xls_loader'
14
14
  module RgGen
15
15
  module SpreadsheetLoader
16
16
  def self.default_setup(builder)
17
- builder.register_loader(:register_map, CSVLoader)
18
- builder.register_loader(:register_map, RooLoader)
19
- builder.register_loader(:register_map, XLSLoader)
17
+ builder.register_loader(:register_map, :spreadsheet, CSVLoader)
18
+ builder.register_loader(:register_map, :spreadsheet, RooLoader)
19
+ builder.register_loader(:register_map, :spreadsheet, XLSLoader)
20
20
  end
21
21
  end
22
22
  end
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rggen/spreadsheet_loader'
4
- RgGen.setup :'rggen-spreadsheet-loader', RgGen::SpreadsheetLoader
4
+ RgGen.setup :'rggen-spreadsheet-loader', RgGen::SpreadsheetLoader do |builder|
5
+ builder.ignore_value :register_map, :spreadsheet, :register_block, :comment
6
+ builder.ignore_value :register_map, :spreadsheet, :register, :comment
7
+ end
@@ -9,72 +9,65 @@ module RgGen
9
9
  Spreadsheet::Book.new(file) { |book| read_spreadsheet(file, book) }
10
10
  end
11
11
 
12
- def format(book, _file)
13
- book.sheets.each(&method(:process_sheet))
14
- end
15
-
16
12
  private
17
13
 
18
- def process_sheet(sheet)
19
- register_block = parse_register_block(sheet)
20
- sheet
21
- .rows(register_start_position.row)
22
- .reject { |row| row.cells.all?(&:empty_cell?) }
23
- .each { |row| process_row(row, register_block) }
14
+ def format_layer_data(read_data, layer, _file)
15
+ layer != :root ? collect_layer_data(read_data, layer) : nil
24
16
  end
25
17
 
26
- def parse_register_block(sheet)
27
- root.register_block do
28
- register_block_valid_values
29
- .zip(register_block_cells(sheet))
30
- .each { |value_name, cell| value(value_name, cell) }
31
- end
18
+ def collect_layer_data(read_data, layer)
19
+ values = valid_values(layer)
20
+ cells = __send__("#{layer}_cells", read_data)
21
+ values.zip(cells).to_h
32
22
  end
33
23
 
34
24
  def register_block_cells(sheet)
35
25
  start_row = register_block_start_position.row
36
26
  start_column = register_block_start_position.column
37
- Array.new(register_block_valid_values.size) do |i|
27
+ Array.new(valid_values(:register_block).size) do |i|
38
28
  sheet[start_row + i, start_column]
39
29
  end
40
30
  end
41
31
 
42
- def process_row(row, register_block)
43
- register =
44
- if row[register_start_position.column].empty_cell?
45
- register_block.children.last
46
- else
47
- parse_register(row, register_block)
48
- end
49
- parse_bit_field(row, register)
32
+ def register_cells(rows)
33
+ start_column = register_start_position.column
34
+ size = valid_values(:register).size
35
+ rows.first.cells(start_column, size)
50
36
  end
51
37
 
52
- def parse_register(row, register_block)
53
- register_block.register do
54
- register_valid_values
55
- .zip(register_cells(row))
56
- .each { |value_name, cell| value(value_name, cell) }
57
- end
38
+ def bit_field_cells(row)
39
+ start_column = bit_field_start_position.column
40
+ size = valid_values(:bit_field).size
41
+ row.cells(start_column, size)
58
42
  end
59
43
 
60
- def register_cells(row)
61
- start_column = register_start_position.column
62
- size = register_valid_values.size
63
- row.cells(start_column, size)
44
+ SUB_LAYERS = {
45
+ root: :register_block,
46
+ register_block: :register,
47
+ register: :bit_field
48
+ }.freeze
49
+
50
+ def format_sub_layer_data(read_data, layer, _file)
51
+ sub_layer = SUB_LAYERS[layer]
52
+ sub_layer && { sub_layer => __send__("collect_#{sub_layer}_data", read_data) }
64
53
  end
65
54
 
66
- def parse_bit_field(row, register)
67
- register.bit_field do
68
- bit_field_valid_values
69
- .zip(bit_field_cells(row))
70
- .each { |value_name, cell| value(value_name, cell) }
71
- end
55
+ def collect_register_block_data(book)
56
+ book.sheets
72
57
  end
73
58
 
74
- def bit_field_cells(row)
75
- start_column = bit_field_start_position.column
76
- size = bit_field_valid_values.size
77
- row.cells(start_column, size)
59
+ def collect_register_data(sheet)
60
+ sheet.rows(register_start_position.row)
61
+ .reject { |row| row.cells.all?(&:empty_cell?) }
62
+ .each_with_object([]) do |row, row_sets|
63
+ row[register_start_position.column].empty_cell? ||
64
+ (row_sets << [])
65
+ row_sets.last << row
66
+ end
67
+ end
68
+
69
+ def collect_bit_field_data(rows)
70
+ rows
78
71
  end
79
72
 
80
73
  def register_block_start_position
@@ -83,29 +76,17 @@ module RgGen
83
76
 
84
77
  def register_start_position
85
78
  @register_start_position ||=
86
- Position.new(register_block_valid_values.size + 2, 1)
79
+ Position.new(valid_values(:register_block).size + 2, 1)
87
80
  end
88
81
 
89
82
  def bit_field_start_position
90
83
  @bit_field_start_position ||=
91
84
  begin
92
85
  column =
93
- register_start_position.column + register_valid_values.size
86
+ register_start_position.column + valid_values(:register).size
94
87
  Position.new(0, column)
95
88
  end
96
89
  end
97
-
98
- def register_block_valid_values
99
- valid_value_lists[:register_block]
100
- end
101
-
102
- def register_valid_values
103
- valid_value_lists[:register]
104
- end
105
-
106
- def bit_field_valid_values
107
- valid_value_lists[:bit_field]
108
- end
109
90
  end
110
91
  end
111
92
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RgGen
4
4
  module SpreadsheetLoader
5
- VERSION = '0.16.0'
5
+ VERSION = '0.17.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rggen-spreadsheet-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roo
@@ -100,5 +100,5 @@ requirements: []
100
100
  rubygems_version: 3.1.2
101
101
  signing_key:
102
102
  specification_version: 4
103
- summary: rggen-spreadsheet-loader-0.16.0
103
+ summary: rggen-spreadsheet-loader-0.17.0
104
104
  test_files: []