rggen-spreadsheet-loader 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 72ae0f3ce551504e8d03a34b60dd745c9ccae7b9029f66e5ea1bffb6fac744b8
4
+ data.tar.gz: 6fd10b3cdc393388de294c080326316d1eb45dd9c7a7e803d234d2392ab8e80d
5
+ SHA512:
6
+ metadata.gz: e5f6e0edac2b6406c0a3abc4981373b1a63898bde5931578450668bcc5d5888ec537b976f94b452279cba9d09b089c6f61a4ed06e4d358ad52b2317eef8b3bcb
7
+ data.tar.gz: ceae9e59744d315fdc3986a9fe274b2555ba74db34b5cebdfda9893184ed0195785d216b2fc8e843239df70b248c1dee08ec263078db4aa2868c6c37293c4579
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at taichi730@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Taichi Ishitani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ [![Build Status](https://travis-ci.org/rggen/rggen-spreadsheet-loader.svg?branch=master)](https://travis-ci.org/rggen/rggen-spreadsheet-loader)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7a4090f4a7c21d29036c/maintainability)](https://codeclimate.com/github/rggen/rggen-spreadsheet-loader/maintainability)
3
+ [![codecov](https://codecov.io/gh/rggen/rggen-spreadsheet-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-spreadsheet-loader)
4
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rggen_rggen-spreadsheet-loader&metric=alert_status)](https://sonarcloud.io/dashboard?id=rggen_rggen-spreadsheet-loader)
5
+
6
+ # RgGen::SpreadsheetLoader
7
+
8
+ RgGen::SpreadsheetLoader adds ability to load register map documents written in spreadsheet format.
9
+
10
+ Supported spreadsheet formats are listed below:
11
+
12
+ * MS Excel (xlsx and xls)
13
+ * LibreOffice/OpenOffice (ods)
14
+ * CSV
15
+
16
+ ## Installation
17
+
18
+ During RgGen installation, RgGen::SpreadsheetLoader will also be isntalled automatically.
19
+
20
+ ```
21
+ $ gem install rggen
22
+ ```
23
+
24
+ If you want to install RgGen::SpreadsheetLoader only, use the command below:
25
+
26
+ ```
27
+ $ gem install rggen-spreadsheet-loader
28
+ ```
29
+
30
+ ## Contact
31
+
32
+ Feedbacks, bug reports, questions and etc. are wellcome! You can post them by using following ways:
33
+
34
+ * [GitHub Issue Tracker](https://github.com/rggen/rggen-spreadsheet-loader/issues)
35
+ * [Mail](mailto:taichi730@gmail.com)
36
+
37
+ ## Copyright & License
38
+
39
+ Copyright © 2019 Taichi Ishitani. RgGen::SpreadsheetLoader is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the RgGen project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rggen/rggen-spreadsheet-loader/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ class RooLoader < Core::RegisterMap::Loader
6
+ include SpreadsheetLoader
7
+
8
+ support_types [:xlsx, :xls, :ods, :csv]
9
+
10
+ def read_spreadsheet(file, book)
11
+ Roo::Spreadsheet.open(file).each_with_pagename do |pagename, page|
12
+ page.first_row && book.add_sheet(pagename, collect_cells(page))
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def collect_cells(page)
19
+ (1..page.last_row).map do |row|
20
+ (1..page.last_column).map { |column| page.cell(row, column) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module Spreadsheet
6
+ class Book
7
+ def initialize(file)
8
+ @file = file
9
+ @sheets = []
10
+ block_given? && yield(self)
11
+ end
12
+
13
+ attr_reader :file
14
+ attr_reader :sheets
15
+
16
+ def add_sheet(sheet_name, table)
17
+ sheet = Sheet.new(self, sheet_name)
18
+ sheet.from_table(table)
19
+ sheets << sheet
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module Spreadsheet
6
+ class Cell < Core::InputBase::InputValue
7
+ def initialize(row, column)
8
+ position = Position.new(row.file, row.sheet, row.row, column)
9
+ super(nil, position)
10
+ end
11
+
12
+ alias_method :empty_cell?, :empty_value?
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module Spreadsheet
6
+ Position = Struct.new(:file, :sheet, :row, :column) do
7
+ def to_s
8
+ to_h
9
+ .map { |field, value| "#{field}: #{value}" }
10
+ .join(' ')
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module Spreadsheet
6
+ class Row
7
+ def initialize(sheet, row)
8
+ @file = sheet.file
9
+ @sheet = sheet.sheet
10
+ @row = row
11
+ @cells = []
12
+ end
13
+
14
+ attr_reader :file
15
+ attr_reader :sheet
16
+ attr_reader :row
17
+
18
+ def [](column)
19
+ @cells[column] ||= Cell.new(self, column)
20
+ @cells[column]
21
+ end
22
+
23
+ def []=(column, value)
24
+ self[column].value = value
25
+ end
26
+
27
+ def cells(from = 0, length = nil)
28
+ Array.new(length || (@cells.size - from)) { |i| self[from + i] }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module Spreadsheet
6
+ class Sheet
7
+ def initialize(book, sheet)
8
+ @file = book.file
9
+ @sheet = sheet
10
+ @rows = []
11
+ end
12
+
13
+ attr_reader :file
14
+ attr_reader :sheet
15
+
16
+ def [](row, column = nil)
17
+ @rows[row] ||= Row.new(self, row)
18
+ (column && @rows[row][column]) || @rows[row]
19
+ end
20
+
21
+ def from_table(table)
22
+ table.each_with_index do |row, row_index|
23
+ row.each_with_index do |value, column_index|
24
+ self[row_index][column_index] = value
25
+ end
26
+ end
27
+ end
28
+
29
+ def rows(from = 0, length = nil)
30
+ Array.new(length || (@rows.size - from)) { |i| self[from + i] }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ module SpreadsheetLoader
6
+ Position = Struct.new(:row, :column)
7
+
8
+ def read_file(file)
9
+ Spreadsheet::Book.new(file) { |book| read_spreadsheet(file, book) }
10
+ end
11
+
12
+ def format(book, _file)
13
+ book.sheets.each(&method(:process_sheet))
14
+ end
15
+
16
+ private
17
+
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) }
24
+ end
25
+
26
+ def parse_register_block(sheet)
27
+ register_map.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
32
+ end
33
+
34
+ def register_block_cells(sheet)
35
+ start_row = register_block_start_position.row
36
+ start_column = register_block_start_position.column
37
+ Array.new(register_block_valid_values.size) do |i|
38
+ sheet[start_row + i, start_column]
39
+ end
40
+ end
41
+
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)
50
+ end
51
+
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
58
+ end
59
+
60
+ def register_cells(row)
61
+ start_column = register_start_position.column
62
+ size = register_valid_values.size
63
+ row.cells(start_column, size)
64
+ end
65
+
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
72
+ end
73
+
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)
78
+ end
79
+
80
+ def register_block_start_position
81
+ @register_block_start_position ||= Position.new(0, 2)
82
+ end
83
+
84
+ def register_start_position
85
+ @register_start_position ||=
86
+ Position.new(register_block_valid_values.size + 2, 1)
87
+ end
88
+
89
+ def bit_field_start_position
90
+ @bit_field_start_position ||=
91
+ begin
92
+ column =
93
+ register_start_position.column + register_valid_values.size
94
+ Position.new(0, column)
95
+ end
96
+ end
97
+
98
+ def register_block_valid_values
99
+ valid_value_lists[1]
100
+ end
101
+
102
+ def register_valid_values
103
+ valid_value_lists[2]
104
+ end
105
+
106
+ def bit_field_valid_values
107
+ valid_value_lists[3]
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SpreadsheetLoader
5
+ VERSION = '0.9.0'
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'roo'
4
+ require 'roo-xls'
5
+ require_relative 'spreadsheet_loader/version'
6
+ require_relative 'spreadsheet_loader/spreadsheet/position'
7
+ require_relative 'spreadsheet_loader/spreadsheet/cell'
8
+ require_relative 'spreadsheet_loader/spreadsheet/row'
9
+ require_relative 'spreadsheet_loader/spreadsheet/sheet'
10
+ require_relative 'spreadsheet_loader/spreadsheet/book'
11
+ require_relative 'spreadsheet_loader/spreadsheet_loader'
12
+ require_relative 'spreadsheet_loader/roo_loader'
13
+
14
+ module RgGen
15
+ module SpreadsheetLoader
16
+ def self.setup(builder)
17
+ builder.register_loader(:register_map, RooLoader)
18
+ end
19
+ end
20
+
21
+ setup :'spreadsheet-loader', SpreadsheetLoader
22
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rggen-spreadsheet-loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Taichi Ishitani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-26 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.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: roo-xls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Spreadsheet loader for RgGen register map.
56
+ email:
57
+ - taichi730@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CODE_OF_CONDUCT.md
63
+ - LICENSE
64
+ - README.md
65
+ - lib/rggen/spreadsheet_loader.rb
66
+ - lib/rggen/spreadsheet_loader/roo_loader.rb
67
+ - lib/rggen/spreadsheet_loader/spreadsheet/book.rb
68
+ - lib/rggen/spreadsheet_loader/spreadsheet/cell.rb
69
+ - lib/rggen/spreadsheet_loader/spreadsheet/position.rb
70
+ - lib/rggen/spreadsheet_loader/spreadsheet/row.rb
71
+ - lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb
72
+ - lib/rggen/spreadsheet_loader/spreadsheet_loader.rb
73
+ - lib/rggen/spreadsheet_loader/version.rb
74
+ homepage: https://github.com/rggen/rggen-spreadsheet-loader
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ bug_tracker_uri: https://github.com/rggen/rggen-spreadsheet-loader/issues
79
+ source_code_uri: https://github.com/rggen/rggen-spreadsheet-loader
80
+ wiki_uri: https://github.com/rggen/rggen/wiki
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '2.3'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: rggen-spreadsheet-loader-0.9.0
100
+ test_files: []