ruh-roo 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +677 -0
  3. data/Gemfile +24 -0
  4. data/LICENSE +24 -0
  5. data/README.md +315 -0
  6. data/lib/roo/base.rb +607 -0
  7. data/lib/roo/constants.rb +7 -0
  8. data/lib/roo/csv.rb +141 -0
  9. data/lib/roo/errors.rb +11 -0
  10. data/lib/roo/excelx/cell/base.rb +108 -0
  11. data/lib/roo/excelx/cell/boolean.rb +30 -0
  12. data/lib/roo/excelx/cell/date.rb +28 -0
  13. data/lib/roo/excelx/cell/datetime.rb +107 -0
  14. data/lib/roo/excelx/cell/empty.rb +20 -0
  15. data/lib/roo/excelx/cell/number.rb +89 -0
  16. data/lib/roo/excelx/cell/string.rb +19 -0
  17. data/lib/roo/excelx/cell/time.rb +44 -0
  18. data/lib/roo/excelx/cell.rb +110 -0
  19. data/lib/roo/excelx/comments.rb +55 -0
  20. data/lib/roo/excelx/coordinate.rb +19 -0
  21. data/lib/roo/excelx/extractor.rb +39 -0
  22. data/lib/roo/excelx/format.rb +71 -0
  23. data/lib/roo/excelx/images.rb +26 -0
  24. data/lib/roo/excelx/relationships.rb +33 -0
  25. data/lib/roo/excelx/shared.rb +39 -0
  26. data/lib/roo/excelx/shared_strings.rb +151 -0
  27. data/lib/roo/excelx/sheet.rb +151 -0
  28. data/lib/roo/excelx/sheet_doc.rb +248 -0
  29. data/lib/roo/excelx/styles.rb +64 -0
  30. data/lib/roo/excelx/workbook.rb +63 -0
  31. data/lib/roo/excelx.rb +480 -0
  32. data/lib/roo/font.rb +17 -0
  33. data/lib/roo/formatters/base.rb +15 -0
  34. data/lib/roo/formatters/csv.rb +84 -0
  35. data/lib/roo/formatters/matrix.rb +23 -0
  36. data/lib/roo/formatters/xml.rb +31 -0
  37. data/lib/roo/formatters/yaml.rb +40 -0
  38. data/lib/roo/helpers/default_attr_reader.rb +20 -0
  39. data/lib/roo/helpers/weak_instance_cache.rb +41 -0
  40. data/lib/roo/libre_office.rb +4 -0
  41. data/lib/roo/link.rb +34 -0
  42. data/lib/roo/open_office.rb +628 -0
  43. data/lib/roo/spreadsheet.rb +39 -0
  44. data/lib/roo/tempdir.rb +21 -0
  45. data/lib/roo/utils.rb +128 -0
  46. data/lib/roo/version.rb +3 -0
  47. data/lib/roo.rb +36 -0
  48. data/roo.gemspec +28 -0
  49. metadata +189 -0
data/lib/roo/utils.rb ADDED
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Roo
4
+ module Utils
5
+ extend self
6
+
7
+ LETTERS = ('A'..'Z').to_a
8
+
9
+ def extract_coordinate(s)
10
+ num = letter_num = 0
11
+ num_only = false
12
+
13
+ s.each_byte do |b|
14
+ if !num_only && (index = char_index(b))
15
+ letter_num *= 26
16
+ letter_num += index
17
+ elsif index = num_index(b)
18
+ num_only = true
19
+ num *= 10
20
+ num += index
21
+ else
22
+ fail ArgumentError
23
+ end
24
+ end
25
+ fail ArgumentError if letter_num == 0 || !num_only
26
+
27
+ Excelx::Coordinate.new(num, letter_num)
28
+ end
29
+
30
+ alias_method :ref_to_key, :extract_coordinate
31
+
32
+ def split_coordinate(str)
33
+ warn "[DEPRECATION] `Roo::Utils.split_coordinate` is deprecated. Please use `Roo::Utils.extract_coordinate` instead."
34
+ extract_coordinate(str)
35
+ end
36
+
37
+
38
+
39
+ def split_coord(str)
40
+ coord = extract_coordinate(str)
41
+ [number_to_letter(coord.column), coord.row]
42
+ end
43
+
44
+ # convert a number to something like 'AB' (1 => 'A', 2 => 'B', ...)
45
+ def number_to_letter(num)
46
+ result = +""
47
+
48
+ until num.zero?
49
+ num, index = (num - 1).divmod(26)
50
+ result.prepend(LETTERS[index])
51
+ end
52
+
53
+ result
54
+ end
55
+
56
+ def letter_to_number(letters)
57
+ @letter_to_number ||= {}
58
+ @letter_to_number[letters] ||= begin
59
+ result = 0
60
+
61
+ # :bytes method returns an enumerator in 1.9.3 and an array in 2.0+
62
+ letters.bytes.to_a.map{|b| b > 96 ? b - 96 : b - 64 }.reverse.each_with_index{ |num, i| result += num * 26 ** i }
63
+
64
+ result
65
+ end
66
+ end
67
+
68
+ # Compute upper bound for cells in a given cell range.
69
+ def num_cells_in_range(str)
70
+ cells = str.split(':')
71
+ return 1 if cells.count == 1
72
+ raise ArgumentError.new("invalid range string: #{str}. Supported range format 'A1:B2'") if cells.count != 2
73
+ x1, y1 = extract_coordinate(cells[0])
74
+ x2, y2 = extract_coordinate(cells[1])
75
+ (x2 - (x1 - 1)) * (y2 - (y1 - 1))
76
+ end
77
+
78
+ def coordinates_in_range(str)
79
+ return to_enum(:coordinates_in_range, str) unless block_given?
80
+ coordinates = str.split(":", 2).map! { |s| extract_coordinate s }
81
+
82
+ case coordinates.size
83
+ when 1
84
+ yield coordinates[0]
85
+ when 2
86
+ tl, br = coordinates
87
+ rows = tl.row..br.row
88
+ cols = tl.column..br.column
89
+ rows.each do |row|
90
+ cols.each do |column|
91
+ yield Excelx::Coordinate.new(row, column)
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ def load_xml(path)
98
+ ::File.open(path, 'rb') do |file|
99
+ ::Nokogiri::XML(file)
100
+ end
101
+ end
102
+
103
+ # Yield each element of a given type ('row', 'c', etc.) to caller
104
+ def each_element(path, elements)
105
+ elements = Array(elements)
106
+ Nokogiri::XML::Reader(::File.open(path, 'rb'), nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).each do |node|
107
+ next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT && elements.include?(node.name)
108
+ yield Nokogiri::XML(node.outer_xml).root if block_given?
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def char_index(byte)
115
+ if byte >= 65 && byte <= 90
116
+ byte - 64
117
+ elsif byte >= 97 && byte <= 122
118
+ byte - 96
119
+ end
120
+ end
121
+
122
+ def num_index(byte)
123
+ if byte >= 48 && byte <= 57
124
+ byte - 48
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module Roo
2
+ VERSION = "3.0.1"
3
+ end
data/lib/roo.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'roo/version'
4
+ require 'roo/constants'
5
+ require 'roo/errors'
6
+ require 'roo/spreadsheet'
7
+ require 'roo/base'
8
+
9
+ module Roo
10
+ autoload :OpenOffice, 'roo/open_office'
11
+ autoload :LibreOffice, 'roo/libre_office'
12
+ autoload :Excelx, 'roo/excelx'
13
+ autoload :CSV, 'roo/csv'
14
+
15
+ TEMP_PREFIX = 'roo_'
16
+
17
+ CLASS_FOR_EXTENSION = {
18
+ ods: Roo::OpenOffice,
19
+ xlsx: Roo::Excelx,
20
+ xlsm: Roo::Excelx,
21
+ csv: Roo::CSV
22
+ }
23
+
24
+ def self.const_missing(const_name)
25
+ case const_name
26
+ when :Excel
27
+ raise ROO_EXCEL_NOTICE
28
+ when :Excel2003XML
29
+ raise ROO_EXCELML_NOTICE
30
+ when :Google
31
+ raise ROO_GOOGLE_NOTICE
32
+ else
33
+ super
34
+ end
35
+ end
36
+ end
data/roo.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'roo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruh-roo'
8
+ spec.version = Roo::VERSION
9
+ spec.authors = ['Thomas Preymesser', 'Hugh McGowan', 'Ben Woosley', 'Oleksandr Simonov', 'Steven Daniels', 'Anmol Chopra']
10
+ spec.email = ['ruby.ruby.ruby.roo@gmail.com', 'oleksandr@simonov.me']
11
+ spec.summary = 'Roo can access the contents of various spreadsheet files.'
12
+ spec.description = "Roo can access the contents of various spreadsheet files. It can handle\n* OpenOffice\n* Excelx\n* LibreOffice\n* CSV"
13
+ spec.homepage = 'https://github.com/rbclark/roo'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.glob('lib/**/*').reject { |f| File.directory?(f) } + %w{CHANGELOG.md LICENSE README.md Gemfile roo.gemspec}
17
+
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.required_ruby_version = ">= 2.5.0"
21
+
22
+ spec.add_dependency 'nokogiri', '~> 1'
23
+ spec.add_dependency 'rubyzip', '>= 1.3.0', '< 3.0.0'
24
+
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
27
+ spec.add_development_dependency 'rack', '~> 1.6', '< 2.0.0'
28
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruh-roo
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Preymesser
8
+ - Hugh McGowan
9
+ - Ben Woosley
10
+ - Oleksandr Simonov
11
+ - Steven Daniels
12
+ - Anmol Chopra
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2021-10-07 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: nokogiri
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - "~>"
23
+ - !ruby/object:Gem::Version
24
+ version: '1'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '1'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rubyzip
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 1.3.0
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: 3.0.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.3.0
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: 3.0.0
52
+ - !ruby/object:Gem::Dependency
53
+ name: rake
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ - !ruby/object:Gem::Dependency
67
+ name: minitest
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '5.4'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 5.4.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.4'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 5.4.3
86
+ - !ruby/object:Gem::Dependency
87
+ name: rack
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '1.6'
93
+ - - "<"
94
+ - !ruby/object:Gem::Version
95
+ version: 2.0.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.6'
103
+ - - "<"
104
+ - !ruby/object:Gem::Version
105
+ version: 2.0.0
106
+ description: |-
107
+ Roo can access the contents of various spreadsheet files. It can handle
108
+ * OpenOffice
109
+ * Excelx
110
+ * LibreOffice
111
+ * CSV
112
+ email:
113
+ - ruby.ruby.ruby.roo@gmail.com
114
+ - oleksandr@simonov.me
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - CHANGELOG.md
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.md
123
+ - lib/roo.rb
124
+ - lib/roo/base.rb
125
+ - lib/roo/constants.rb
126
+ - lib/roo/csv.rb
127
+ - lib/roo/errors.rb
128
+ - lib/roo/excelx.rb
129
+ - lib/roo/excelx/cell.rb
130
+ - lib/roo/excelx/cell/base.rb
131
+ - lib/roo/excelx/cell/boolean.rb
132
+ - lib/roo/excelx/cell/date.rb
133
+ - lib/roo/excelx/cell/datetime.rb
134
+ - lib/roo/excelx/cell/empty.rb
135
+ - lib/roo/excelx/cell/number.rb
136
+ - lib/roo/excelx/cell/string.rb
137
+ - lib/roo/excelx/cell/time.rb
138
+ - lib/roo/excelx/comments.rb
139
+ - lib/roo/excelx/coordinate.rb
140
+ - lib/roo/excelx/extractor.rb
141
+ - lib/roo/excelx/format.rb
142
+ - lib/roo/excelx/images.rb
143
+ - lib/roo/excelx/relationships.rb
144
+ - lib/roo/excelx/shared.rb
145
+ - lib/roo/excelx/shared_strings.rb
146
+ - lib/roo/excelx/sheet.rb
147
+ - lib/roo/excelx/sheet_doc.rb
148
+ - lib/roo/excelx/styles.rb
149
+ - lib/roo/excelx/workbook.rb
150
+ - lib/roo/font.rb
151
+ - lib/roo/formatters/base.rb
152
+ - lib/roo/formatters/csv.rb
153
+ - lib/roo/formatters/matrix.rb
154
+ - lib/roo/formatters/xml.rb
155
+ - lib/roo/formatters/yaml.rb
156
+ - lib/roo/helpers/default_attr_reader.rb
157
+ - lib/roo/helpers/weak_instance_cache.rb
158
+ - lib/roo/libre_office.rb
159
+ - lib/roo/link.rb
160
+ - lib/roo/open_office.rb
161
+ - lib/roo/spreadsheet.rb
162
+ - lib/roo/tempdir.rb
163
+ - lib/roo/utils.rb
164
+ - lib/roo/version.rb
165
+ - roo.gemspec
166
+ homepage: https://github.com/rbclark/roo
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: 2.5.0
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubygems_version: 3.1.6
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Roo can access the contents of various spreadsheet files.
189
+ test_files: []