roo 1.13.2 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.github/ISSUE_TEMPLATE +10 -0
  4. data/.gitignore +11 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +17 -0
  7. data/CHANGELOG.md +626 -0
  8. data/Gemfile +17 -12
  9. data/Gemfile_ruby2 +30 -0
  10. data/Guardfile +23 -0
  11. data/LICENSE +3 -1
  12. data/README.md +285 -0
  13. data/Rakefile +23 -23
  14. data/examples/roo_soap_client.rb +28 -31
  15. data/examples/roo_soap_server.rb +4 -6
  16. data/examples/write_me.rb +9 -10
  17. data/lib/roo/base.rb +298 -495
  18. data/lib/roo/constants.rb +5 -0
  19. data/lib/roo/csv.rb +127 -113
  20. data/lib/roo/errors.rb +11 -0
  21. data/lib/roo/excelx/cell/base.rb +94 -0
  22. data/lib/roo/excelx/cell/boolean.rb +27 -0
  23. data/lib/roo/excelx/cell/date.rb +28 -0
  24. data/lib/roo/excelx/cell/datetime.rb +111 -0
  25. data/lib/roo/excelx/cell/empty.rb +19 -0
  26. data/lib/roo/excelx/cell/number.rb +87 -0
  27. data/lib/roo/excelx/cell/string.rb +19 -0
  28. data/lib/roo/excelx/cell/time.rb +43 -0
  29. data/lib/roo/excelx/cell.rb +106 -0
  30. data/lib/roo/excelx/comments.rb +55 -0
  31. data/lib/roo/excelx/coordinate.rb +12 -0
  32. data/lib/roo/excelx/extractor.rb +21 -0
  33. data/lib/roo/excelx/format.rb +64 -0
  34. data/lib/roo/excelx/relationships.rb +25 -0
  35. data/lib/roo/excelx/shared.rb +32 -0
  36. data/lib/roo/excelx/shared_strings.rb +157 -0
  37. data/lib/roo/excelx/sheet.rb +112 -0
  38. data/lib/roo/excelx/sheet_doc.rb +211 -0
  39. data/lib/roo/excelx/styles.rb +64 -0
  40. data/lib/roo/excelx/workbook.rb +59 -0
  41. data/lib/roo/excelx.rb +376 -602
  42. data/lib/roo/font.rb +17 -0
  43. data/lib/roo/formatters/base.rb +15 -0
  44. data/lib/roo/formatters/csv.rb +84 -0
  45. data/lib/roo/formatters/matrix.rb +23 -0
  46. data/lib/roo/formatters/xml.rb +31 -0
  47. data/lib/roo/formatters/yaml.rb +40 -0
  48. data/lib/roo/libre_office.rb +4 -0
  49. data/lib/roo/link.rb +34 -0
  50. data/lib/roo/open_office.rb +626 -0
  51. data/lib/roo/spreadsheet.rb +22 -23
  52. data/lib/roo/tempdir.rb +21 -0
  53. data/lib/roo/utils.rb +78 -0
  54. data/lib/roo/version.rb +3 -0
  55. data/lib/roo.rb +23 -24
  56. data/roo.gemspec +21 -204
  57. data/spec/helpers.rb +5 -0
  58. data/spec/lib/roo/base_spec.rb +229 -3
  59. data/spec/lib/roo/csv_spec.rb +38 -11
  60. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  61. data/spec/lib/roo/excelx_spec.rb +510 -11
  62. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  63. data/spec/lib/roo/openoffice_spec.rb +30 -8
  64. data/spec/lib/roo/spreadsheet_spec.rb +60 -12
  65. data/spec/lib/roo/utils_spec.rb +106 -0
  66. data/spec/spec_helper.rb +7 -6
  67. data/test/all_ss.rb +12 -11
  68. data/test/excelx/cell/test_base.rb +63 -0
  69. data/test/excelx/cell/test_boolean.rb +36 -0
  70. data/test/excelx/cell/test_date.rb +38 -0
  71. data/test/excelx/cell/test_datetime.rb +45 -0
  72. data/test/excelx/cell/test_empty.rb +7 -0
  73. data/test/excelx/cell/test_number.rb +74 -0
  74. data/test/excelx/cell/test_string.rb +28 -0
  75. data/test/excelx/cell/test_time.rb +30 -0
  76. data/test/formatters/test_csv.rb +119 -0
  77. data/test/formatters/test_matrix.rb +76 -0
  78. data/test/formatters/test_xml.rb +74 -0
  79. data/test/formatters/test_yaml.rb +20 -0
  80. data/test/roo/test_csv.rb +52 -0
  81. data/test/roo/test_excelx.rb +186 -0
  82. data/test/roo/test_libre_office.rb +9 -0
  83. data/test/roo/test_open_office.rb +126 -0
  84. data/test/test_helper.rb +73 -53
  85. data/test/test_roo.rb +1211 -2292
  86. metadata +119 -298
  87. data/CHANGELOG +0 -417
  88. data/Gemfile.lock +0 -78
  89. data/README.markdown +0 -126
  90. data/VERSION +0 -1
  91. data/lib/roo/excel.rb +0 -355
  92. data/lib/roo/excel2003xml.rb +0 -300
  93. data/lib/roo/google.rb +0 -292
  94. data/lib/roo/openoffice.rb +0 -496
  95. data/lib/roo/roo_rails_helper.rb +0 -83
  96. data/lib/roo/worksheet.rb +0 -18
  97. data/scripts/txt2html +0 -67
  98. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  99. data/spec/lib/roo/excel_spec.rb +0 -17
  100. data/spec/lib/roo/google_spec.rb +0 -64
  101. data/test/files/1900_base.xls +0 -0
  102. data/test/files/1900_base.xlsx +0 -0
  103. data/test/files/1904_base.xls +0 -0
  104. data/test/files/1904_base.xlsx +0 -0
  105. data/test/files/Bibelbund.csv +0 -3741
  106. data/test/files/Bibelbund.ods +0 -0
  107. data/test/files/Bibelbund.xls +0 -0
  108. data/test/files/Bibelbund.xlsx +0 -0
  109. data/test/files/Bibelbund.xml +0 -62518
  110. data/test/files/Bibelbund1.ods +0 -0
  111. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  112. data/test/files/bad_excel_date.xls +0 -0
  113. data/test/files/bbu.ods +0 -0
  114. data/test/files/bbu.xls +0 -0
  115. data/test/files/bbu.xlsx +0 -0
  116. data/test/files/bbu.xml +0 -152
  117. data/test/files/bode-v1.ods.zip +0 -0
  118. data/test/files/bode-v1.xls.zip +0 -0
  119. data/test/files/boolean.csv +0 -2
  120. data/test/files/boolean.ods +0 -0
  121. data/test/files/boolean.xls +0 -0
  122. data/test/files/boolean.xlsx +0 -0
  123. data/test/files/boolean.xml +0 -112
  124. data/test/files/borders.ods +0 -0
  125. data/test/files/borders.xls +0 -0
  126. data/test/files/borders.xlsx +0 -0
  127. data/test/files/borders.xml +0 -144
  128. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  129. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  130. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  131. data/test/files/comments.ods +0 -0
  132. data/test/files/comments.xls +0 -0
  133. data/test/files/comments.xlsx +0 -0
  134. data/test/files/csvtypes.csv +0 -1
  135. data/test/files/datetime.ods +0 -0
  136. data/test/files/datetime.xls +0 -0
  137. data/test/files/datetime.xlsx +0 -0
  138. data/test/files/datetime.xml +0 -142
  139. data/test/files/datetime_floatconv.xls +0 -0
  140. data/test/files/datetime_floatconv.xml +0 -148
  141. data/test/files/dreimalvier.ods +0 -0
  142. data/test/files/emptysheets.ods +0 -0
  143. data/test/files/emptysheets.xls +0 -0
  144. data/test/files/emptysheets.xlsx +0 -0
  145. data/test/files/emptysheets.xml +0 -105
  146. data/test/files/excel2003.xml +0 -21140
  147. data/test/files/false_encoding.xls +0 -0
  148. data/test/files/false_encoding.xml +0 -132
  149. data/test/files/file_item_error.xlsx +0 -0
  150. data/test/files/formula.ods +0 -0
  151. data/test/files/formula.xls +0 -0
  152. data/test/files/formula.xlsx +0 -0
  153. data/test/files/formula.xml +0 -134
  154. data/test/files/formula_parse_error.xls +0 -0
  155. data/test/files/formula_parse_error.xml +0 -1833
  156. data/test/files/formula_string_error.xlsx +0 -0
  157. data/test/files/html-escape.ods +0 -0
  158. data/test/files/link.xls +0 -0
  159. data/test/files/link.xlsx +0 -0
  160. data/test/files/matrix.ods +0 -0
  161. data/test/files/matrix.xls +0 -0
  162. data/test/files/named_cells.ods +0 -0
  163. data/test/files/named_cells.xls +0 -0
  164. data/test/files/named_cells.xlsx +0 -0
  165. data/test/files/no_spreadsheet_file.txt +0 -1
  166. data/test/files/numbers1.csv +0 -18
  167. data/test/files/numbers1.ods +0 -0
  168. data/test/files/numbers1.xls +0 -0
  169. data/test/files/numbers1.xlsx +0 -0
  170. data/test/files/numbers1.xml +0 -312
  171. data/test/files/numeric-link.xlsx +0 -0
  172. data/test/files/only_one_sheet.ods +0 -0
  173. data/test/files/only_one_sheet.xls +0 -0
  174. data/test/files/only_one_sheet.xlsx +0 -0
  175. data/test/files/only_one_sheet.xml +0 -67
  176. data/test/files/paragraph.ods +0 -0
  177. data/test/files/paragraph.xls +0 -0
  178. data/test/files/paragraph.xlsx +0 -0
  179. data/test/files/paragraph.xml +0 -127
  180. data/test/files/prova.xls +0 -0
  181. data/test/files/ric.ods +0 -0
  182. data/test/files/simple_spreadsheet.ods +0 -0
  183. data/test/files/simple_spreadsheet.xls +0 -0
  184. data/test/files/simple_spreadsheet.xlsx +0 -0
  185. data/test/files/simple_spreadsheet.xml +0 -225
  186. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  187. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  188. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  189. data/test/files/so_datetime.csv +0 -7
  190. data/test/files/style.ods +0 -0
  191. data/test/files/style.xls +0 -0
  192. data/test/files/style.xlsx +0 -0
  193. data/test/files/style.xml +0 -154
  194. data/test/files/time-test.csv +0 -2
  195. data/test/files/time-test.ods +0 -0
  196. data/test/files/time-test.xls +0 -0
  197. data/test/files/time-test.xlsx +0 -0
  198. data/test/files/time-test.xml +0 -131
  199. data/test/files/type_excel.ods +0 -0
  200. data/test/files/type_excel.xlsx +0 -0
  201. data/test/files/type_excelx.ods +0 -0
  202. data/test/files/type_excelx.xls +0 -0
  203. data/test/files/type_openoffice.xls +0 -0
  204. data/test/files/type_openoffice.xlsx +0 -0
  205. data/test/files/whitespace.ods +0 -0
  206. data/test/files/whitespace.xls +0 -0
  207. data/test/files/whitespace.xlsx +0 -0
  208. data/test/files/whitespace.xml +0 -184
  209. data/test/rm_sub_test.rb +0 -12
  210. data/test/rm_test.rb +0 -7
  211. data/test/test_generic_spreadsheet.rb +0 -259
  212. data/website/index.html +0 -385
  213. data/website/index.txt +0 -423
  214. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  215. data/website/stylesheets/screen.css +0 -130
  216. data/website/template.rhtml +0 -48
data/lib/roo/utils.rb ADDED
@@ -0,0 +1,78 @@
1
+ module Roo
2
+ module Utils
3
+ extend self
4
+
5
+ LETTERS = ('A'..'Z').to_a
6
+
7
+ def split_coordinate(str)
8
+ @split_coordinate ||= {}
9
+
10
+ @split_coordinate[str] ||= begin
11
+ letter, number = split_coord(str)
12
+ x = letter_to_number(letter)
13
+ y = number
14
+ [y, x]
15
+ end
16
+ end
17
+
18
+ alias_method :ref_to_key, :split_coordinate
19
+
20
+ def split_coord(s)
21
+ if s =~ /([a-zA-Z]+)([0-9]+)/
22
+ letter = Regexp.last_match[1]
23
+ number = Regexp.last_match[2].to_i
24
+ else
25
+ fail ArgumentError
26
+ end
27
+ [letter, number]
28
+ end
29
+
30
+ # convert a number to something like 'AB' (1 => 'A', 2 => 'B', ...)
31
+ def number_to_letter(num)
32
+ result = ""
33
+
34
+ until num.zero?
35
+ num, index = (num - 1).divmod(26)
36
+ result.prepend(LETTERS[index])
37
+ end
38
+
39
+ result
40
+ end
41
+
42
+ def letter_to_number(letters)
43
+ @letter_to_number ||= {}
44
+ @letter_to_number[letters] ||= begin
45
+ result = 0
46
+
47
+ # :bytes method returns an enumerator in 1.9.3 and an array in 2.0+
48
+ letters.bytes.to_a.map{|b| b > 96 ? b - 96 : b - 64 }.reverse.each_with_index{ |num, i| result += num * 26 ** i }
49
+
50
+ result
51
+ end
52
+ end
53
+
54
+ # Compute upper bound for cells in a given cell range.
55
+ def num_cells_in_range(str)
56
+ cells = str.split(':')
57
+ return 1 if cells.count == 1
58
+ raise ArgumentError.new("invalid range string: #{str}. Supported range format 'A1:B2'") if cells.count != 2
59
+ x1, y1 = split_coordinate(cells[0])
60
+ x2, y2 = split_coordinate(cells[1])
61
+ (x2 - (x1 - 1)) * (y2 - (y1 - 1))
62
+ end
63
+
64
+ def load_xml(path)
65
+ ::File.open(path, 'rb') do |file|
66
+ ::Nokogiri::XML(file)
67
+ end
68
+ end
69
+
70
+ # Yield each element of a given type ('row', 'c', etc.) to caller
71
+ def each_element(path, elements)
72
+ Nokogiri::XML::Reader(::File.open(path, 'rb'), nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).each do |node|
73
+ next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT && Array(elements).include?(node.name)
74
+ yield Nokogiri::XML(node.outer_xml).root if block_given?
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Roo
2
+ VERSION = "2.7.0"
3
+ end
data/lib/roo.rb CHANGED
@@ -1,34 +1,33 @@
1
+ require 'roo/constants'
2
+ require 'roo/errors'
3
+ require 'roo/spreadsheet'
4
+ require 'roo/base'
5
+
1
6
  module Roo
7
+ autoload :OpenOffice, 'roo/open_office'
8
+ autoload :LibreOffice, 'roo/libre_office'
9
+ autoload :Excelx, 'roo/excelx'
10
+ autoload :CSV, 'roo/csv'
11
+
12
+ TEMP_PREFIX = 'roo_'.freeze
2
13
 
3
- VERSION = '1.12.1'
14
+ CLASS_FOR_EXTENSION = {
15
+ ods: Roo::OpenOffice,
16
+ xlsx: Roo::Excelx,
17
+ xlsm: Roo::Excelx,
18
+ csv: Roo::CSV
19
+ }
4
20
 
5
21
  def self.const_missing(const_name)
6
22
  case const_name
7
- when :Libreoffice
8
- warn "`Roo::Libreoffice` has been deprecated. Use `Roo::LibreOffice` instead."
9
- LibreOffice
10
- when :Openoffice
11
- warn "`Roo::Openoffice` has been deprecated. Use `Roo::OpenOffice` instead."
12
- OpenOffice
13
- when :Csv
14
- warn "`Roo::Csv` has been deprecated. Use `Roo::CSV` instead."
15
- CSV
16
- when :GenericSpreadsheet
17
- warn "`Roo::GenericSpreadsheet` has been deprecated. Use `Roo::Base` instead."
18
- Base
23
+ when :Excel
24
+ raise ROO_EXCEL_NOTICE
25
+ when :Excel2003XML
26
+ raise ROO_EXCELML_NOTICE
27
+ when :Google
28
+ raise ROO_GOOGLE_NOTICE
19
29
  else
20
30
  super
21
31
  end
22
32
  end
23
-
24
- autoload :Spreadsheet, 'roo/spreadsheet'
25
- autoload :Base, 'roo/base'
26
-
27
- autoload :OpenOffice, 'roo/openoffice'
28
- autoload :LibreOffice, 'roo/openoffice'
29
- autoload :Excel, 'roo/excel'
30
- autoload :Excelx, 'roo/excelx'
31
- autoload :Excel2003XML, 'roo/excel2003xml'
32
- autoload :Google, 'roo/google'
33
- autoload :CSV, 'roo/csv'
34
33
  end
data/roo.gemspec CHANGED
@@ -1,209 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
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
5
 
6
- Gem::Specification.new do |s|
7
- s.name = "roo"
8
- s.version = "1.13.2"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'roo'
8
+ spec.version = Roo::VERSION
9
+ spec.authors = ['Thomas Preymesser', 'Hugh McGowan', 'Ben Woosley', 'Oleksandr Simonov', 'Steven Daniels']
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 = 'http://github.com/roo-rb/roo'
14
+ spec.license = 'MIT'
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Thomas Preymesser", "Hugh McGowan", "Ben Woosley"]
12
- s.date = "2013-12-23"
13
- s.description = "Roo can access the contents of various spreadsheet files. It can handle\n* OpenOffice\n* Excel\n* Google spreadsheets\n* Excelx\n* LibreOffice\n* CSV"
14
- s.email = "ruby.ruby.ruby.roo@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- "CHANGELOG",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE",
24
- "README.markdown",
25
- "Rakefile",
26
- "VERSION",
27
- "examples/roo_soap_client.rb",
28
- "examples/roo_soap_server.rb",
29
- "examples/write_me.rb",
30
- "lib/roo.rb",
31
- "lib/roo/base.rb",
32
- "lib/roo/csv.rb",
33
- "lib/roo/excel.rb",
34
- "lib/roo/excel2003xml.rb",
35
- "lib/roo/excelx.rb",
36
- "lib/roo/google.rb",
37
- "lib/roo/openoffice.rb",
38
- "lib/roo/roo_rails_helper.rb",
39
- "lib/roo/spreadsheet.rb",
40
- "lib/roo/worksheet.rb",
41
- "roo.gemspec",
42
- "scripts/txt2html",
43
- "spec/fixtures/vcr_cassettes/google_drive.yml",
44
- "spec/fixtures/vcr_cassettes/google_drive_access_token.yml",
45
- "spec/fixtures/vcr_cassettes/google_drive_set.yml",
46
- "spec/lib/roo/base_spec.rb",
47
- "spec/lib/roo/csv_spec.rb",
48
- "spec/lib/roo/excel2003xml_spec.rb",
49
- "spec/lib/roo/excel_spec.rb",
50
- "spec/lib/roo/excelx/format_spec.rb",
51
- "spec/lib/roo/excelx_spec.rb",
52
- "spec/lib/roo/google_spec.rb",
53
- "spec/lib/roo/libreoffice_spec.rb",
54
- "spec/lib/roo/openoffice_spec.rb",
55
- "spec/lib/roo/spreadsheet_spec.rb",
56
- "spec/spec_helper.rb",
57
- "test/all_ss.rb",
58
- "test/files/1900_base.xls",
59
- "test/files/1900_base.xlsx",
60
- "test/files/1904_base.xls",
61
- "test/files/1904_base.xlsx",
62
- "test/files/Bibelbund.csv",
63
- "test/files/Bibelbund.ods",
64
- "test/files/Bibelbund.xls",
65
- "test/files/Bibelbund.xlsx",
66
- "test/files/Bibelbund.xml",
67
- "test/files/Bibelbund1.ods",
68
- "test/files/Pfand_from_windows_phone.xlsx",
69
- "test/files/bad_excel_date.xls",
70
- "test/files/bbu.ods",
71
- "test/files/bbu.xls",
72
- "test/files/bbu.xlsx",
73
- "test/files/bbu.xml",
74
- "test/files/bode-v1.ods.zip",
75
- "test/files/bode-v1.xls.zip",
76
- "test/files/boolean.csv",
77
- "test/files/boolean.ods",
78
- "test/files/boolean.xls",
79
- "test/files/boolean.xlsx",
80
- "test/files/boolean.xml",
81
- "test/files/borders.ods",
82
- "test/files/borders.xls",
83
- "test/files/borders.xlsx",
84
- "test/files/borders.xml",
85
- "test/files/bug-numbered-sheet-names.xlsx",
86
- "test/files/bug-row-column-fixnum-float.xls",
87
- "test/files/bug-row-column-fixnum-float.xml",
88
- "test/files/comments.ods",
89
- "test/files/comments.xls",
90
- "test/files/comments.xlsx",
91
- "test/files/csvtypes.csv",
92
- "test/files/datetime.ods",
93
- "test/files/datetime.xls",
94
- "test/files/datetime.xlsx",
95
- "test/files/datetime.xml",
96
- "test/files/datetime_floatconv.xls",
97
- "test/files/datetime_floatconv.xml",
98
- "test/files/dreimalvier.ods",
99
- "test/files/emptysheets.ods",
100
- "test/files/emptysheets.xls",
101
- "test/files/emptysheets.xlsx",
102
- "test/files/emptysheets.xml",
103
- "test/files/excel2003.xml",
104
- "test/files/false_encoding.xls",
105
- "test/files/false_encoding.xml",
106
- "test/files/file_item_error.xlsx",
107
- "test/files/formula.ods",
108
- "test/files/formula.xls",
109
- "test/files/formula.xlsx",
110
- "test/files/formula.xml",
111
- "test/files/formula_parse_error.xls",
112
- "test/files/formula_parse_error.xml",
113
- "test/files/formula_string_error.xlsx",
114
- "test/files/html-escape.ods",
115
- "test/files/link.xls",
116
- "test/files/link.xlsx",
117
- "test/files/matrix.ods",
118
- "test/files/matrix.xls",
119
- "test/files/named_cells.ods",
120
- "test/files/named_cells.xls",
121
- "test/files/named_cells.xlsx",
122
- "test/files/no_spreadsheet_file.txt",
123
- "test/files/numbers1.csv",
124
- "test/files/numbers1.ods",
125
- "test/files/numbers1.xls",
126
- "test/files/numbers1.xlsx",
127
- "test/files/numbers1.xml",
128
- "test/files/numeric-link.xlsx",
129
- "test/files/only_one_sheet.ods",
130
- "test/files/only_one_sheet.xls",
131
- "test/files/only_one_sheet.xlsx",
132
- "test/files/only_one_sheet.xml",
133
- "test/files/paragraph.ods",
134
- "test/files/paragraph.xls",
135
- "test/files/paragraph.xlsx",
136
- "test/files/paragraph.xml",
137
- "test/files/prova.xls",
138
- "test/files/ric.ods",
139
- "test/files/simple_spreadsheet.ods",
140
- "test/files/simple_spreadsheet.xls",
141
- "test/files/simple_spreadsheet.xlsx",
142
- "test/files/simple_spreadsheet.xml",
143
- "test/files/simple_spreadsheet_from_italo.ods",
144
- "test/files/simple_spreadsheet_from_italo.xls",
145
- "test/files/simple_spreadsheet_from_italo.xml",
146
- "test/files/so_datetime.csv",
147
- "test/files/style.ods",
148
- "test/files/style.xls",
149
- "test/files/style.xlsx",
150
- "test/files/style.xml",
151
- "test/files/time-test.csv",
152
- "test/files/time-test.ods",
153
- "test/files/time-test.xls",
154
- "test/files/time-test.xlsx",
155
- "test/files/time-test.xml",
156
- "test/files/type_excel.ods",
157
- "test/files/type_excel.xlsx",
158
- "test/files/type_excelx.ods",
159
- "test/files/type_excelx.xls",
160
- "test/files/type_openoffice.xls",
161
- "test/files/type_openoffice.xlsx",
162
- "test/files/whitespace.ods",
163
- "test/files/whitespace.xls",
164
- "test/files/whitespace.xlsx",
165
- "test/files/whitespace.xml",
166
- "test/rm_sub_test.rb",
167
- "test/rm_test.rb",
168
- "test/test_generic_spreadsheet.rb",
169
- "test/test_helper.rb",
170
- "test/test_roo.rb",
171
- "website/index.html",
172
- "website/index.txt",
173
- "website/javascripts/rounded_corners_lite.inc.js",
174
- "website/stylesheets/screen.css",
175
- "website/template.rhtml"
176
- ]
177
- s.homepage = "http://github.com/Empact/roo"
178
- s.licenses = ["MIT"]
179
- s.require_paths = ["lib"]
180
- s.required_ruby_version = Gem::Requirement.new(">= 1.9.0")
181
- s.rubygems_version = "2.0.14"
182
- s.summary = "Roo can access the contents of various spreadsheet files."
183
- s.test_files = ["spec/fixtures/vcr_cassettes/google_drive.yml", "spec/fixtures/vcr_cassettes/google_drive_access_token.yml", "spec/fixtures/vcr_cassettes/google_drive_set.yml", "spec/lib/roo/base_spec.rb", "spec/lib/roo/csv_spec.rb", "spec/lib/roo/excel2003xml_spec.rb", "spec/lib/roo/excel_spec.rb", "spec/lib/roo/excelx/format_spec.rb", "spec/lib/roo/excelx_spec.rb", "spec/lib/roo/google_spec.rb", "spec/lib/roo/libreoffice_spec.rb", "spec/lib/roo/openoffice_spec.rb", "spec/lib/roo/spreadsheet_spec.rb", "spec/spec_helper.rb", "test/all_ss.rb", "test/files/1900_base.xls", "test/files/1900_base.xlsx", "test/files/1904_base.xls", "test/files/1904_base.xlsx", "test/files/Bibelbund.csv", "test/files/Bibelbund.ods", "test/files/Bibelbund.xls", "test/files/Bibelbund.xlsx", "test/files/Bibelbund.xml", "test/files/Bibelbund1.ods", "test/files/Pfand_from_windows_phone.xlsx", "test/files/bad_excel_date.xls", "test/files/bbu.ods", "test/files/bbu.xls", "test/files/bbu.xlsx", "test/files/bbu.xml", "test/files/bode-v1.ods.zip", "test/files/bode-v1.xls.zip", "test/files/boolean.csv", "test/files/boolean.ods", "test/files/boolean.xls", "test/files/boolean.xlsx", "test/files/boolean.xml", "test/files/borders.ods", "test/files/borders.xls", "test/files/borders.xlsx", "test/files/borders.xml", "test/files/bug-numbered-sheet-names.xlsx", "test/files/bug-row-column-fixnum-float.xls", "test/files/bug-row-column-fixnum-float.xml", "test/files/comments.ods", "test/files/comments.xls", "test/files/comments.xlsx", "test/files/csvtypes.csv", "test/files/datetime.ods", "test/files/datetime.xls", "test/files/datetime.xlsx", "test/files/datetime.xml", "test/files/datetime_floatconv.xls", "test/files/datetime_floatconv.xml", "test/files/dreimalvier.ods", "test/files/emptysheets.ods", "test/files/emptysheets.xls", "test/files/emptysheets.xlsx", "test/files/emptysheets.xml", "test/files/excel2003.xml", "test/files/false_encoding.xls", "test/files/false_encoding.xml", "test/files/file_item_error.xlsx", "test/files/formula.ods", "test/files/formula.xls", "test/files/formula.xlsx", "test/files/formula.xml", "test/files/formula_parse_error.xls", "test/files/formula_parse_error.xml", "test/files/formula_string_error.xlsx", "test/files/html-escape.ods", "test/files/link.xls", "test/files/link.xlsx", "test/files/matrix.ods", "test/files/matrix.xls", "test/files/named_cells.ods", "test/files/named_cells.xls", "test/files/named_cells.xlsx", "test/files/no_spreadsheet_file.txt", "test/files/numbers1.csv", "test/files/numbers1.ods", "test/files/numbers1.xls", "test/files/numbers1.xlsx", "test/files/numbers1.xml", "test/files/numeric-link.xlsx", "test/files/only_one_sheet.ods", "test/files/only_one_sheet.xls", "test/files/only_one_sheet.xlsx", "test/files/only_one_sheet.xml", "test/files/paragraph.ods", "test/files/paragraph.xls", "test/files/paragraph.xlsx", "test/files/paragraph.xml", "test/files/prova.xls", "test/files/ric.ods", "test/files/simple_spreadsheet.ods", "test/files/simple_spreadsheet.xls", "test/files/simple_spreadsheet.xlsx", "test/files/simple_spreadsheet.xml", "test/files/simple_spreadsheet_from_italo.ods", "test/files/simple_spreadsheet_from_italo.xls", "test/files/simple_spreadsheet_from_italo.xml", "test/files/so_datetime.csv", "test/files/style.ods", "test/files/style.xls", "test/files/style.xlsx", "test/files/style.xml", "test/files/time-test.csv", "test/files/time-test.ods", "test/files/time-test.xls", "test/files/time-test.xlsx", "test/files/time-test.xml", "test/files/type_excel.ods", "test/files/type_excel.xlsx", "test/files/type_excelx.ods", "test/files/type_excelx.xls", "test/files/type_openoffice.xls", "test/files/type_openoffice.xlsx", "test/files/whitespace.ods", "test/files/whitespace.xls", "test/files/whitespace.xlsx", "test/files/whitespace.xml", "test/rm_sub_test.rb", "test/rm_test.rb", "test/test_generic_spreadsheet.rb", "test/test_helper.rb", "test/test_roo.rb"]
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.files.reject! { |fn| fn.include?('test/files') }
18
+ spec.require_paths = ['lib']
184
19
 
185
- if s.respond_to? :specification_version then
186
- s.specification_version = 4
20
+ spec.add_dependency 'nokogiri', '~> 1'
21
+ spec.add_dependency 'rubyzip', '~> 1.1', '< 2.0.0'
187
22
 
188
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
189
- s.add_runtime_dependency(%q<spreadsheet>, ["> 0.6.4"])
190
- s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
191
- s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
192
- s.add_development_dependency(%q<google_drive>, [">= 0"])
193
- s.add_development_dependency(%q<jeweler>, [">= 0"])
194
- else
195
- s.add_dependency(%q<spreadsheet>, ["> 0.6.4"])
196
- s.add_dependency(%q<nokogiri>, [">= 0"])
197
- s.add_dependency(%q<rubyzip>, [">= 0"])
198
- s.add_dependency(%q<google_drive>, [">= 0"])
199
- s.add_dependency(%q<jeweler>, [">= 0"])
200
- end
201
- else
202
- s.add_dependency(%q<spreadsheet>, ["> 0.6.4"])
203
- s.add_dependency(%q<nokogiri>, [">= 0"])
204
- s.add_dependency(%q<rubyzip>, [">= 0"])
205
- s.add_dependency(%q<google_drive>, [">= 0"])
206
- s.add_dependency(%q<jeweler>, [">= 0"])
207
- end
23
+ spec.add_development_dependency 'rake', '~> 10.1'
24
+ spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
25
+ spec.add_development_dependency 'rack', '~> 1.6', '< 2.0.0'
208
26
  end
209
-
data/spec/helpers.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Helpers
2
+ def yaml_entry(row,col,type,value)
3
+ "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
4
+ end
5
+ end
@@ -1,7 +1,233 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Roo::GenericSpreadsheet do
4
- it 'is an alias of Base' do
5
- expect(Roo::GenericSpreadsheet).to eq(Roo::Base)
3
+ describe Roo::Base do
4
+ let(:klass) do
5
+ Class.new(Roo::Base) do
6
+ def initialize(filename, data = {})
7
+ super(filename)
8
+ @data ||= data
9
+ end
10
+
11
+ def read_cells(sheet = default_sheet)
12
+ return if @cells_read[sheet]
13
+ type_map = { String => :string, Date => :date, Numeric => :float }
14
+
15
+ @cell[sheet] = @data
16
+ @cell_type[sheet] = Hash[@data.map { |k, v| [k, type_map.find {|type,_| v.is_a?(type) }.last ] }]
17
+ @first_row[sheet] = @data.map { |k, _| k[0] }.min
18
+ @last_row[sheet] = @data.map { |k, _| k[0] }.max
19
+ @first_column[sheet] = @data.map { |k, _| k[1] }.min
20
+ @last_column[sheet] = @data.map { |k, _| k[1] }.max
21
+ @cells_read[sheet] = true
22
+ end
23
+
24
+ def cell(row, col, sheet = nil)
25
+ sheet ||= default_sheet
26
+ read_cells(sheet)
27
+ @cell[sheet][[row, col]]
28
+ end
29
+
30
+ def celltype(row, col, sheet = nil)
31
+ sheet ||= default_sheet
32
+ read_cells(sheet)
33
+ @cell_type[sheet][[row, col]]
34
+ end
35
+
36
+ def sheets
37
+ ['my_sheet', 'blank sheet']
38
+ end
39
+ end
40
+ end
41
+
42
+ let(:spreadsheet_data) do
43
+ {
44
+ [3, 1] => 'Header',
45
+
46
+ [5, 1] => Date.civil(1961, 11, 21),
47
+
48
+ [8, 3] => 'thisisc8',
49
+ [8, 7] => 'thisisg8',
50
+
51
+ [12, 1] => 41.0,
52
+ [12, 2] => 42.0,
53
+ [12, 3] => 43.0,
54
+ [12, 4] => 44.0,
55
+ [12, 5] => 45.0,
56
+
57
+ [15, 3] => 43.0,
58
+ [15, 4] => 44.0,
59
+ [15, 5] => 45.0,
60
+
61
+ [16, 2] => '"Hello world!"',
62
+ [16, 3] => 'forty-three',
63
+ [16, 4] => 'forty-four',
64
+ [16, 5] => 'forty-five'
65
+ }
66
+ end
67
+
68
+ let(:spreadsheet) { klass.new('some_file', spreadsheet_data) }
69
+
70
+ describe '#uri?' do
71
+ it 'should return true when passed a filename starting with http(s)://' do
72
+ expect(spreadsheet.send(:uri?, 'http://example.com/')).to be_truthy
73
+ expect(spreadsheet.send(:uri?, 'https://example.com/')).to be_truthy
74
+ end
75
+
76
+ it 'should return false when passed a filename which does not start with http(s)://' do
77
+ expect(spreadsheet.send(:uri?, 'example.com')).to be_falsy
78
+ end
79
+
80
+ it 'should return false when passed non-String object such as Tempfile' do
81
+ expect(spreadsheet.send(:uri?, Tempfile.new('test'))).to be_falsy
82
+ end
83
+ end
84
+
85
+ describe '#set' do
86
+ it 'should not update cell when setting an invalid type' do
87
+ spreadsheet.set(1, 1, 1)
88
+ expect { spreadsheet.set(1, 1, :invalid_type) }.to raise_error(ArgumentError)
89
+ expect(spreadsheet.cell(1, 1)).to eq(1)
90
+ expect(spreadsheet.celltype(1, 1)).to eq(:float)
91
+ end
92
+ end
93
+
94
+ describe '#first_row' do
95
+ it 'should return the first row' do
96
+ expect(spreadsheet.first_row).to eq(3)
97
+ end
98
+ end
99
+
100
+ describe '#last_row' do
101
+ it 'should return the last row' do
102
+ expect(spreadsheet.last_row).to eq(16)
103
+ end
104
+ end
105
+
106
+ describe '#first_column' do
107
+ it 'should return the first column' do
108
+ expect(spreadsheet.first_column).to eq(1)
109
+ end
110
+ end
111
+
112
+ describe '#first_column_as_letter' do
113
+ it 'should return the first column as a letter' do
114
+ expect(spreadsheet.first_column_as_letter).to eq('A')
115
+ end
116
+ end
117
+
118
+ describe '#last_column' do
119
+ it 'should return the last column' do
120
+ expect(spreadsheet.last_column).to eq(7)
121
+ end
122
+ end
123
+
124
+ describe '#last_column_as_letter' do
125
+ it 'should return the last column as a letter' do
126
+ expect(spreadsheet.last_column_as_letter).to eq('G')
127
+ end
128
+ end
129
+
130
+ describe '#row' do
131
+ it 'should return the specified row' do
132
+ expect(spreadsheet.row(12)).to eq([41.0, 42.0, 43.0, 44.0, 45.0, nil, nil])
133
+ expect(spreadsheet.row(16)).to eq([nil, '"Hello world!"', 'forty-three', 'forty-four', 'forty-five', nil, nil])
134
+ end
135
+ end
136
+
137
+ describe '#row_with' do
138
+ context 'with a matching header row' do
139
+ it 'returns the row number' do
140
+ expect(spreadsheet.row_with([/Header/])). to eq 3
141
+ end
142
+ end
143
+
144
+ context 'without a matching header row' do
145
+ it 'raises an error' do
146
+ expect { spreadsheet.row_with([/Missing Header/]) }.to \
147
+ raise_error(Roo::HeaderRowNotFoundError)
148
+ end
149
+ end
150
+ end
151
+
152
+ describe '#empty?' do
153
+ it 'should return true when empty' do
154
+ expect(spreadsheet.empty?(1, 1)).to be_truthy
155
+ expect(spreadsheet.empty?(8, 3)).to be_falsy
156
+ expect(spreadsheet.empty?('A', 11)).to be_truthy
157
+ expect(spreadsheet.empty?('A', 12)).to be_falsy
158
+ end
159
+ end
160
+
161
+ describe '#reload' do
162
+ it 'should return reinitialize the spreadsheet' do
163
+ spreadsheet.reload
164
+ expect(spreadsheet.instance_variable_get(:@cell).empty?).to be_truthy
165
+ end
166
+ end
167
+
168
+ describe '#each' do
169
+ it 'should return an enumerator with all the rows' do
170
+ each = spreadsheet.each
171
+ expect(each).to be_a(Enumerator)
172
+ expect(each.to_a.last).to eq([nil, '"Hello world!"', 'forty-three', 'forty-four', 'forty-five', nil, nil])
173
+ end
174
+ end
175
+
176
+ describe '#to_yaml' do
177
+ it 'should convert the spreadsheet to yaml' do
178
+ expect(spreadsheet.to_yaml({}, 5, 1, 5, 1)).to eq("--- \n" + yaml_entry(5, 1, 'date', '1961-11-21'))
179
+ expect(spreadsheet.to_yaml({}, 8, 3, 8, 3)).to eq("--- \n" + yaml_entry(8, 3, 'string', 'thisisc8'))
180
+
181
+ expect(spreadsheet.to_yaml({}, 12, 3, 12, 3)).to eq("--- \n" + yaml_entry(12, 3, 'float', 43.0))
182
+
183
+ expect(spreadsheet.to_yaml({}, 12, 3, 12)).to eq(
184
+ "--- \n" + yaml_entry(12, 3, 'float', 43.0) +
185
+ yaml_entry(12, 4, 'float', 44.0) +
186
+ yaml_entry(12, 5, 'float', 45.0))
187
+
188
+ expect(spreadsheet.to_yaml({}, 12, 3)).to eq(
189
+ "--- \n" + yaml_entry(12, 3, 'float', 43.0) +
190
+ yaml_entry(12, 4, 'float', 44.0) +
191
+ yaml_entry(12, 5, 'float', 45.0) +
192
+ yaml_entry(15, 3, 'float', 43.0) +
193
+ yaml_entry(15, 4, 'float', 44.0) +
194
+ yaml_entry(15, 5, 'float', 45.0) +
195
+ yaml_entry(16, 3, 'string', 'forty-three') +
196
+ yaml_entry(16, 4, 'string', 'forty-four') +
197
+ yaml_entry(16, 5, 'string', 'forty-five'))
198
+ end
199
+ end
200
+
201
+ let(:expected_csv) do
202
+ <<EOS
203
+ ,,,,,,
204
+ ,,,,,,
205
+ "Header",,,,,,
206
+ ,,,,,,
207
+ 1961-11-21,,,,,,
208
+ ,,,,,,
209
+ ,,,,,,
210
+ ,,"thisisc8",,,,"thisisg8"
211
+ ,,,,,,
212
+ ,,,,,,
213
+ ,,,,,,
214
+ 41,42,43,44,45,,
215
+ ,,,,,,
216
+ ,,,,,,
217
+ ,,43,44,45,,
218
+ ,"""Hello world!""","forty-three","forty-four","forty-five",,
219
+ EOS
220
+ end
221
+
222
+ let(:expected_csv_with_semicolons) { expected_csv.gsub(/\,/, ';') }
223
+
224
+ describe '#to_csv' do
225
+ it 'should convert the spreadsheet to csv' do
226
+ expect(spreadsheet.to_csv).to eq(expected_csv)
227
+ end
228
+
229
+ it 'should convert the spreadsheet to csv using the separator when is passed on the parameter' do
230
+ expect(spreadsheet.to_csv(nil, ';')).to eq(expected_csv_with_semicolons)
231
+ end
6
232
  end
7
233
  end