roo 2.0.1 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.github/ISSUE_TEMPLATE +10 -0
  4. data/.gitignore +4 -0
  5. data/.travis.yml +10 -6
  6. data/CHANGELOG.md +116 -1
  7. data/Gemfile +3 -4
  8. data/Gemfile_ruby2 +30 -0
  9. data/Guardfile +1 -2
  10. data/README.md +56 -22
  11. data/Rakefile +1 -1
  12. data/lib/roo/base.rb +108 -245
  13. data/lib/roo/constants.rb +5 -0
  14. data/lib/roo/csv.rb +94 -87
  15. data/lib/roo/errors.rb +11 -0
  16. data/lib/roo/excelx/cell/base.rb +94 -0
  17. data/lib/roo/excelx/cell/boolean.rb +27 -0
  18. data/lib/roo/excelx/cell/date.rb +28 -0
  19. data/lib/roo/excelx/cell/datetime.rb +111 -0
  20. data/lib/roo/excelx/cell/empty.rb +19 -0
  21. data/lib/roo/excelx/cell/number.rb +87 -0
  22. data/lib/roo/excelx/cell/string.rb +19 -0
  23. data/lib/roo/excelx/cell/time.rb +43 -0
  24. data/lib/roo/excelx/cell.rb +33 -4
  25. data/lib/roo/excelx/comments.rb +33 -0
  26. data/lib/roo/excelx/coordinate.rb +12 -0
  27. data/lib/roo/excelx/extractor.rb +3 -4
  28. data/lib/roo/excelx/format.rb +64 -0
  29. data/lib/roo/excelx/shared.rb +32 -0
  30. data/lib/roo/excelx/shared_strings.rb +124 -4
  31. data/lib/roo/excelx/sheet.rb +12 -7
  32. data/lib/roo/excelx/sheet_doc.rb +108 -97
  33. data/lib/roo/excelx/styles.rb +1 -1
  34. data/lib/roo/excelx.rb +61 -103
  35. data/lib/roo/formatters/base.rb +15 -0
  36. data/lib/roo/formatters/csv.rb +84 -0
  37. data/lib/roo/formatters/matrix.rb +23 -0
  38. data/lib/roo/formatters/xml.rb +31 -0
  39. data/lib/roo/formatters/yaml.rb +40 -0
  40. data/lib/roo/libre_office.rb +1 -2
  41. data/lib/roo/link.rb +21 -2
  42. data/lib/roo/open_office.rb +468 -523
  43. data/lib/roo/spreadsheet.rb +3 -1
  44. data/lib/roo/tempdir.rb +21 -0
  45. data/lib/roo/utils.rb +7 -7
  46. data/lib/roo/version.rb +1 -1
  47. data/lib/roo.rb +8 -3
  48. data/roo.gemspec +2 -1
  49. data/spec/helpers.rb +5 -0
  50. data/spec/lib/roo/base_spec.rb +229 -0
  51. data/spec/lib/roo/csv_spec.rb +19 -0
  52. data/spec/lib/roo/excelx_spec.rb +97 -11
  53. data/spec/lib/roo/openoffice_spec.rb +18 -1
  54. data/spec/lib/roo/spreadsheet_spec.rb +20 -0
  55. data/spec/lib/roo/utils_spec.rb +1 -1
  56. data/spec/spec_helper.rb +5 -5
  57. data/test/all_ss.rb +12 -11
  58. data/test/excelx/cell/test_base.rb +63 -0
  59. data/test/excelx/cell/test_boolean.rb +36 -0
  60. data/test/excelx/cell/test_date.rb +38 -0
  61. data/test/excelx/cell/test_datetime.rb +45 -0
  62. data/test/excelx/cell/test_empty.rb +7 -0
  63. data/test/excelx/cell/test_number.rb +74 -0
  64. data/test/excelx/cell/test_string.rb +28 -0
  65. data/test/excelx/cell/test_time.rb +30 -0
  66. data/test/formatters/test_csv.rb +119 -0
  67. data/test/formatters/test_matrix.rb +76 -0
  68. data/test/formatters/test_xml.rb +78 -0
  69. data/test/formatters/test_yaml.rb +20 -0
  70. data/test/helpers/test_accessing_files.rb +60 -0
  71. data/test/helpers/test_comments.rb +43 -0
  72. data/test/helpers/test_formulas.rb +9 -0
  73. data/test/helpers/test_labels.rb +103 -0
  74. data/test/helpers/test_sheets.rb +55 -0
  75. data/test/helpers/test_styles.rb +62 -0
  76. data/test/roo/test_base.rb +182 -0
  77. data/test/roo/test_csv.rb +60 -0
  78. data/test/roo/test_excelx.rb +325 -0
  79. data/test/roo/test_libre_office.rb +9 -0
  80. data/test/roo/test_open_office.rb +289 -0
  81. data/test/test_helper.rb +116 -18
  82. data/test/test_roo.rb +362 -2088
  83. metadata +70 -4
  84. data/test/test_generic_spreadsheet.rb +0 -237
data/test/test_helper.rb CHANGED
@@ -1,26 +1,47 @@
1
- require 'simplecov'
2
- # require deps
3
- require 'tmpdir'
4
- require 'fileutils'
5
- require 'minitest/autorun'
6
- require 'shoulda'
7
- require 'fileutils'
8
- require 'timeout'
9
- require 'logger'
10
- require 'date'
11
- require 'webmock/minitest'
1
+ # encoding: utf-8
2
+ require "simplecov"
3
+ require "tmpdir"
4
+ require "fileutils"
5
+ require "minitest/autorun"
6
+ require "shoulda"
7
+ require "timeout"
8
+ require "logger"
9
+ require "date"
12
10
 
13
11
  # require gem files
14
- require 'roo'
12
+ require "roo"
13
+ require "minitest/reporters"
14
+ if ENV["USE_REPORTERS"]
15
+ Minitest::Reporters.use!(
16
+ [
17
+ Minitest::Reporters::DefaultReporter.new,
18
+ Minitest::Reporters::SpecReporter.new
19
+ ]
20
+ )
21
+ end
22
+
23
+ TESTDIR = File.join(File.dirname(__FILE__), "files")
24
+ ROO_FORMATS = [
25
+ :excelx,
26
+ :excelxm,
27
+ :openoffice,
28
+ :libreoffice
29
+ ]
30
+
31
+ require "helpers/test_accessing_files"
32
+ require "helpers/test_comments"
33
+ require "helpers/test_formulas"
34
+ require "helpers/test_labels"
35
+ require "helpers/test_sheets"
36
+ require "helpers/test_styles"
15
37
 
16
- TESTDIR = File.join(File.dirname(__FILE__), 'files')
17
38
 
18
39
  # very simple diff implementation
19
40
  # output is an empty string if the files are equal
20
41
  # otherwise differences a printen (not compatible to
21
42
  # the diff command)
22
43
  def file_diff(fn1,fn2)
23
- result = ''
44
+ result = ""
24
45
  File.open(fn1) do |f1|
25
46
  File.open(fn2) do |f2|
26
47
  while f1.eof? == false and f2.eof? == false
@@ -45,10 +66,6 @@ def file_diff(fn1,fn2)
45
66
  result
46
67
  end
47
68
 
48
- def yaml_entry(row,col,type,value)
49
- "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
50
- end
51
-
52
69
  class File
53
70
  def File.delete_if_exist(filename)
54
71
  if File.exist?(filename)
@@ -56,3 +73,84 @@ class File
56
73
  end
57
74
  end
58
75
  end
76
+
77
+ def local_server(port)
78
+ raise ArgumentError unless port.to_i > 0
79
+ "http://0.0.0.0:#{port}"
80
+ end
81
+
82
+ def start_local_server(filename, port = nil)
83
+ require "rack"
84
+ content_type = filename.split(".").last
85
+ port ||= TEST_RACK_PORT
86
+
87
+ web_server = Proc.new do |env|
88
+ [
89
+ "200",
90
+ { "Content-Type" => content_type },
91
+ [File.read("#{TESTDIR}/#{filename}")]
92
+ ]
93
+ end
94
+
95
+ t = Thread.new { Rack::Handler::WEBrick.run web_server, Host: "0.0.0.0", Port: port , Logger: WEBrick::BasicLog.new(nil,1) }
96
+ # give the app a chance to startup
97
+ sleep(0.2)
98
+
99
+ yield
100
+ ensure
101
+ t.kill
102
+ end
103
+
104
+ # call a block of code for each spreadsheet type
105
+ # and yield a reference to the roo object
106
+ def with_each_spreadsheet(options)
107
+ if options[:format]
108
+ formats = Array(options[:format])
109
+ invalid_formats = formats - ROO_FORMATS
110
+ unless invalid_formats.empty?
111
+ raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
112
+ end
113
+ else
114
+ formats = ROO_FORMATS
115
+ end
116
+ formats.each do |format|
117
+ begin
118
+ yield Roo::Spreadsheet.open(File.join(TESTDIR,
119
+ fixture_filename(options[:name], format)))
120
+ rescue => e
121
+ raise e, "#{e.message} for #{format}", e.backtrace unless options[:ignore_errors]
122
+ end
123
+ end
124
+ end
125
+
126
+ def get_extension(oo)
127
+ case oo
128
+ when Roo::OpenOffice
129
+ ".ods"
130
+ when Roo::Excelx
131
+ ".xlsx"
132
+ end
133
+ end
134
+
135
+ def fixture_filename(name, format)
136
+ case format
137
+ when :excelx
138
+ "#{name}.xlsx"
139
+ when :excelxm
140
+ "#{name}.xlsm"
141
+ when :openoffice, :libreoffice
142
+ "#{name}.ods"
143
+ else
144
+ raise ArgumentError, "unexpected format #{format}"
145
+ end
146
+ end
147
+
148
+ def skip_long_test
149
+ msg = "This is very slow, test use `LONG_RUN=true bundle exec rake` to run it"
150
+ skip(msg) unless ENV["LONG_RUN"]
151
+ end
152
+
153
+ def skip_jruby_incompatible_test
154
+ msg = "This test uses a feature incompatible with JRuby"
155
+ skip(msg) if defined?(JRUBY_VERSION)
156
+ end