spreadsheet_architect 2.1.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +17 -2
  3. data/README.md +149 -129
  4. data/lib/spreadsheet_architect/class_methods/csv.rb +2 -2
  5. data/lib/spreadsheet_architect/class_methods/ods.rb +2 -2
  6. data/lib/spreadsheet_architect/class_methods/xlsx.rb +26 -30
  7. data/lib/spreadsheet_architect/exceptions.rb +32 -30
  8. data/lib/spreadsheet_architect/utils/xlsx.rb +46 -25
  9. data/lib/spreadsheet_architect/utils.rb +116 -121
  10. data/lib/spreadsheet_architect/version.rb +1 -1
  11. data/lib/spreadsheet_architect.rb +5 -1
  12. data/test/dummy_app/app/models/active_model_object.rb +1 -0
  13. data/test/dummy_app/app/models/custom_post.rb +1 -0
  14. data/test/dummy_app/app/models/legacy_plain_ruby_object.rb +14 -0
  15. data/test/dummy_app/app/models/plain_ruby_object.rb +2 -9
  16. data/test/dummy_app/app/models/post.rb +3 -0
  17. data/test/dummy_app/config/routes.rb +4 -5
  18. data/test/dummy_app/db/test.sqlite3 +0 -0
  19. data/test/dummy_app/log/test.log +26911 -21739
  20. data/test/dummy_app/tmp/2.0.1/integration/alt_xlsx.xlsx +0 -0
  21. data/test/dummy_app/tmp/2.0.1/integration/csv.csv +6 -0
  22. data/test/dummy_app/tmp/2.0.1/integration/ods.ods +0 -0
  23. data/test/dummy_app/tmp/2.0.1/integration/xlsx.xlsx +0 -0
  24. data/test/dummy_app/tmp/2.0.1/kitchen_sink.ods +0 -0
  25. data/test/dummy_app/tmp/2.0.1/kitchen_sink.xlsx +0 -0
  26. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.csv +3 -0
  27. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.ods +0 -0
  28. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.xlsx +0 -0
  29. data/test/dummy_app/tmp/{empty_sa.csv → 2.0.1/models/ActiveModelObject/empty.csv} +0 -0
  30. data/test/dummy_app/tmp/{ods/empty_model.ods → 2.0.1/models/ActiveModelObject/empty.ods} +0 -0
  31. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/empty.xlsx +0 -0
  32. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.csv +6 -0
  33. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.ods +0 -0
  34. data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.xlsx +0 -0
  35. data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.csv +3 -0
  36. data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.ods +0 -0
  37. data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.xlsx +0 -0
  38. data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.csv +1 -0
  39. data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.ods +0 -0
  40. data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.xlsx +0 -0
  41. data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.csv +6 -0
  42. data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.ods +0 -0
  43. data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.xlsx +0 -0
  44. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.csv +3 -0
  45. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.ods +0 -0
  46. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.xlsx +0 -0
  47. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.csv +1 -0
  48. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.ods +0 -0
  49. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.xlsx +0 -0
  50. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.csv +6 -0
  51. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.ods +0 -0
  52. data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.xlsx +0 -0
  53. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.csv +3 -0
  54. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.ods +0 -0
  55. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.xlsx +0 -0
  56. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.csv +0 -0
  57. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.ods +0 -0
  58. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.xlsx +0 -0
  59. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.csv +6 -0
  60. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.ods +0 -0
  61. data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.xlsx +0 -0
  62. data/test/dummy_app/tmp/2.0.1/models/Post/data.csv +3 -0
  63. data/test/dummy_app/tmp/2.0.1/models/Post/data.ods +0 -0
  64. data/test/dummy_app/tmp/2.0.1/models/Post/data.xlsx +0 -0
  65. data/test/dummy_app/tmp/2.0.1/models/Post/empty.csv +0 -0
  66. data/test/dummy_app/tmp/2.0.1/models/Post/empty.ods +0 -0
  67. data/test/dummy_app/tmp/2.0.1/models/Post/empty.xlsx +0 -0
  68. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.csv +3 -0
  69. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.ods +0 -0
  70. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/data.xlsx +0 -0
  71. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.csv +0 -0
  72. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.ods +0 -0
  73. data/test/dummy_app/tmp/2.0.1/models/SpreadsheetArchitect/empty.xlsx +0 -0
  74. data/test/dummy_app/tmp/2.0.1/multi_sheet.ods +0 -0
  75. data/test/dummy_app/tmp/2.0.1/multi_sheet.xlsx +0 -0
  76. data/test/dummy_app/tmp/3.0.0.pre/integration/alt_xlsx.xlsx +0 -0
  77. data/test/dummy_app/tmp/3.0.0.pre/integration/csv.csv +6 -0
  78. data/test/dummy_app/tmp/3.0.0.pre/integration/ods.ods +0 -0
  79. data/test/dummy_app/tmp/3.0.0.pre/integration/xlsx.xlsx +0 -0
  80. data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.ods +0 -0
  81. data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.xlsx +0 -0
  82. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.csv +3 -0
  83. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.ods +0 -0
  84. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.xlsx +0 -0
  85. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.csv +0 -0
  86. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.ods +0 -0
  87. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.xlsx +0 -0
  88. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.csv +6 -0
  89. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.ods +0 -0
  90. data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.xlsx +0 -0
  91. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.csv +3 -0
  92. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.ods +0 -0
  93. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.xlsx +0 -0
  94. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.csv +1 -0
  95. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.ods +0 -0
  96. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.xlsx +0 -0
  97. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.csv +6 -0
  98. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.ods +0 -0
  99. data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.xlsx +0 -0
  100. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.csv +3 -0
  101. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.ods +0 -0
  102. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.xlsx +0 -0
  103. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.csv +0 -0
  104. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.ods +0 -0
  105. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.xlsx +0 -0
  106. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.csv +6 -0
  107. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.ods +0 -0
  108. data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.xlsx +0 -0
  109. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.csv +3 -0
  110. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.ods +0 -0
  111. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.xlsx +0 -0
  112. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.csv +1 -0
  113. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.ods +0 -0
  114. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.xlsx +0 -0
  115. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.csv +6 -0
  116. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.ods +0 -0
  117. data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.xlsx +0 -0
  118. data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.csv +3 -0
  119. data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.ods +0 -0
  120. data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.xlsx +0 -0
  121. data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.csv +0 -0
  122. data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.ods +0 -0
  123. data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.xlsx +0 -0
  124. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.csv +3 -0
  125. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.ods +0 -0
  126. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/data.xlsx +0 -0
  127. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.csv +0 -0
  128. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.ods +0 -0
  129. data/test/dummy_app/tmp/3.0.0.pre/models/SpreadsheetArchitect/empty.xlsx +0 -0
  130. data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.ods +0 -0
  131. data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.xlsx +0 -0
  132. data/test/dummy_app/tmp/axlsx-master/integration/alt_xlsx.xlsx +0 -0
  133. data/test/dummy_app/tmp/axlsx-master/integration/csv.csv +6 -0
  134. data/test/dummy_app/tmp/axlsx-master/integration/ods.ods +0 -0
  135. data/test/dummy_app/tmp/axlsx-master/integration/xlsx.xlsx +0 -0
  136. data/test/dummy_app/tmp/axlsx-master/kitchen_sink.ods +0 -0
  137. data/test/dummy_app/tmp/axlsx-master/kitchen_sink.xlsx +0 -0
  138. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.csv +3 -0
  139. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.ods +0 -0
  140. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.xlsx +0 -0
  141. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.csv +0 -0
  142. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.ods +0 -0
  143. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.xlsx +0 -0
  144. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.csv +6 -0
  145. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.ods +0 -0
  146. data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.xlsx +0 -0
  147. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.csv +3 -0
  148. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.ods +0 -0
  149. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.xlsx +0 -0
  150. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.csv +0 -0
  151. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.ods +0 -0
  152. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.xlsx +0 -0
  153. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.csv +6 -0
  154. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.ods +0 -0
  155. data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.xlsx +0 -0
  156. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.csv +3 -0
  157. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.ods +0 -0
  158. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.xlsx +0 -0
  159. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.csv +1 -0
  160. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.ods +0 -0
  161. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.xlsx +0 -0
  162. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.csv +6 -0
  163. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.ods +0 -0
  164. data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.xlsx +0 -0
  165. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.csv +3 -0
  166. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.ods +0 -0
  167. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.xlsx +0 -0
  168. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.csv +1 -0
  169. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.ods +0 -0
  170. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.xlsx +0 -0
  171. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.csv +6 -0
  172. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.ods +0 -0
  173. data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.xlsx +0 -0
  174. data/test/dummy_app/tmp/axlsx-master/models/Post/data.csv +3 -0
  175. data/test/dummy_app/tmp/axlsx-master/models/Post/data.ods +0 -0
  176. data/test/dummy_app/tmp/axlsx-master/models/Post/data.xlsx +0 -0
  177. data/test/dummy_app/tmp/axlsx-master/models/Post/empty.csv +0 -0
  178. data/test/dummy_app/tmp/axlsx-master/models/Post/empty.ods +0 -0
  179. data/test/dummy_app/tmp/axlsx-master/models/Post/empty.xlsx +0 -0
  180. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.csv +3 -0
  181. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.ods +0 -0
  182. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/data.xlsx +0 -0
  183. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.csv +0 -0
  184. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.ods +0 -0
  185. data/test/dummy_app/tmp/axlsx-master/models/SpreadsheetArchitect/empty.xlsx +0 -0
  186. data/test/dummy_app/tmp/axlsx-master/multi_sheet.ods +0 -0
  187. data/test/dummy_app/tmp/axlsx-master/multi_sheet.xlsx +0 -0
  188. data/test/integration/application_test.rb +8 -11
  189. data/test/models/all_models_test.rb +107 -0
  190. data/test/test_helper.rb +13 -4
  191. data/test/unit/exceptions_test.rb +168 -0
  192. data/test/unit/formats_test.rb +15 -0
  193. data/test/unit/general_test.rb +15 -0
  194. data/test/unit/kitchen_sink_test.rb +87 -0
  195. data/test/unit/multi_sheet_test.rb +29 -0
  196. data/test/unit/utils_test.rb +179 -0
  197. data/test/unit/xlsx_utils_test.rb +143 -0
  198. metadata +409 -116
  199. data/lib/generators/spreadsheet_architect/add_project_defaults_generator.rb +0 -20
  200. data/test/dummy_app/app/models/bad_plain_ruby_object.rb +0 -3
  201. data/test/dummy_app/app/views/reports/sample.html.erb +0 -1
  202. data/test/dummy_app/log/development.log +0 -28
  203. data/test/dummy_app/tmp/active_model_object/csv.csv +0 -21
  204. data/test/dummy_app/tmp/active_model_object/ods.ods +0 -0
  205. data/test/dummy_app/tmp/active_model_object/xlsx.xlsx +0 -0
  206. data/test/dummy_app/tmp/custom_posts/csv.csv +0 -6
  207. data/test/dummy_app/tmp/custom_posts/empty.xlsx +0 -0
  208. data/test/dummy_app/tmp/custom_posts/ods.ods +0 -0
  209. data/test/dummy_app/tmp/custom_posts/xlsx.xlsx +0 -0
  210. data/test/dummy_app/tmp/empty_model.csv +0 -1
  211. data/test/dummy_app/tmp/empty_model.xlsx +0 -0
  212. data/test/dummy_app/tmp/empty_sa.xlsx +0 -0
  213. data/test/dummy_app/tmp/extreme.xlsx +0 -0
  214. data/test/dummy_app/tmp/integration_tests/alt_xlsx.xlsx +0 -0
  215. data/test/dummy_app/tmp/integration_tests/csv.csv +0 -6
  216. data/test/dummy_app/tmp/integration_tests/ods.ods +0 -0
  217. data/test/dummy_app/tmp/integration_tests/xlsx.xlsx +0 -0
  218. data/test/dummy_app/tmp/model.csv +0 -6
  219. data/test/dummy_app/tmp/model.xlsx +0 -0
  220. data/test/dummy_app/tmp/ods/empty_sa.ods +0 -0
  221. data/test/dummy_app/tmp/ods/model.ods +0 -0
  222. data/test/dummy_app/tmp/ods/model_options.ods +0 -0
  223. data/test/dummy_app/tmp/ods/sa.ods +0 -0
  224. data/test/dummy_app/tmp/options.csv +0 -6
  225. data/test/dummy_app/tmp/plain_ruby_object/csv.csv +0 -4
  226. data/test/dummy_app/tmp/plain_ruby_object/ods.ods +0 -0
  227. data/test/dummy_app/tmp/plain_ruby_object/xlsx.xlsx +0 -0
  228. data/test/dummy_app/tmp/posts/csv.csv +0 -6
  229. data/test/dummy_app/tmp/posts/empty.xlsx +0 -0
  230. data/test/dummy_app/tmp/posts/ods.ods +0 -0
  231. data/test/dummy_app/tmp/posts/xlsx.xlsx +0 -0
  232. data/test/dummy_app/tmp/sa.csv +0 -4
  233. data/test/dummy_app/tmp/sa.xlsx +0 -0
  234. data/test/models/active_model_object_test.rb +0 -51
  235. data/test/models/bad_plain_ruby_object_test.rb +0 -28
  236. data/test/models/csv_test.rb +0 -59
  237. data/test/models/custom_post_test.rb +0 -51
  238. data/test/models/ods_test.rb +0 -65
  239. data/test/models/plain_ruby_object_test.rb +0 -51
  240. data/test/models/post_test.rb +0 -44
  241. data/test/models/spreadsheet_architect_utils_test.rb +0 -73
  242. data/test/models/xlsx_test.rb +0 -98
  243. data/test/spreadsheet_architect_test.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 474157fbe056d50db456c3e0e65d77fbde737da1
4
- data.tar.gz: 68267aadc938513a444ecd93d823ca83de63029f
2
+ SHA256:
3
+ metadata.gz: 9373288a5139e4300488dc26c66aa5783ddca415a5a01c9b509b7e19a4716055
4
+ data.tar.gz: c8c58c68932e5fc5e36c3f73c3b5d106e90261a64bdbf046fa133e940c2fbb94
5
5
  SHA512:
6
- metadata.gz: b42dde6e402a01ee682a7455febf6b17321bd9a6d7ce0576604579de59144832ac199de239a5949cac2bd7368ff13afd4a3756352e24c37e8d22a61378cc3677
7
- data.tar.gz: fa76fc322e042d98b094729bc1f558ec052bf90bec3acb6de851b0b316f633d19094b6e38607d2e10bea72e1b94f00e40e7342e04c19045974fdc429e276006b
6
+ metadata.gz: ef1f1ac7cd4187c9dae74efcc001099cc190a39a11f7f15341c0649dfac21c13347f8f537274a664e6365229d31a32b58dc60786ea3f7127fdfd18828ba91175
7
+ data.tar.gz: 84b8abd050f5924b25ba15012dde4cd5500ad85de2fa16149c0d0eda0e3fa85ef49370a7d3d5f6a2f3c7ede3f176c6ca23fae02e811bf18711b3b6c3e2fbc09f
data/CHANGELOG.md CHANGED
@@ -1,13 +1,28 @@
1
1
  CHANGELOG
2
2
  ---------
3
3
 
4
+ - **3.0.0** - July 6, 2018
5
+ - [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Add ability to pass :instances option to SpreadsheetArchitect class methods
6
+ - [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Remove Plain Ruby syntax `Post.to_xlsx(instances: posts_array)` in favor of `SpreadsheetArchitect.to_xlsx(instance: posts_array)`. However, it may still work at this time if configured correctly.
7
+ - Fix project-wide and model-level defaults before only `header_style`, `row_style`, & `sheet_name` were being utilized.
8
+ - When using on an ActiveRecord class and `spreadsheet_columns` is not defined, it now defaults to the classes `column_names` only. Previously it would use `column_names` and then remove the following columns `['id', 'created_at', 'updated_at', 'deleted_at']`
9
+ - XLSX column ranges now also accept letters. For example: `{columns: ('C'..'E')}`
10
+ - `:column_types` now considers types defined in `spreadsheet_columns` and class/project-wide defaults. Before it was incorrectly ignored.
11
+ - Passing the `spreadsheet_columns` options now only accepts lambda/proc
12
+ - More type checking and Option types are now being type checked. Option types were supposed to be properly type checked but due to a bug were being skipped.
13
+ - Utilize ActiveSupport `pluralize`, if available, for default sheet names for class-based spreadsheets
14
+ - Renamed `BadRangeError` to `InvalidRangeError`
15
+ - Renamed `IncorrectTypeError` to `InvalidTypeError`
16
+ - Remove all Rails generators `spreadsheet_architect:add_default_options`. No need since its just as easy to copy from the README
17
+ - Major overhaul of test suite, add a ton more tests, for DRYness use resursion for tests when appropriate
18
+ - Use appraisal to test various `axlsx` versions
4
19
  - **2.1.2** - July 6, 2018
5
20
  - Fix bug where everything was underlined by default in Excel (LibreOffice was working correctly). For some reason, `false` in `:u` or `:underline` was incorrectly being treated as `true` but only within Excel. Now anytime `false` is encountered for either `:u` or `:underline` it is now converted to `nil`
6
21
  - Fix bug where empty xlsx spreadsheets were corrupt when trying to open with Excel (LibreOffice was working correctly). This only occured when containing no headers and empty `:data` option which resulted in a package with no sheets.
7
22
  - **2.1.1** - July 4, 2018
8
- - [PR #18](https://github.com/westonganger/spreadsheet_architect/pull/18) - Fix controller bug when using an non-ActiveRecord ORM only within Rails
23
+ - [#18](https://github.com/westonganger/spreadsheet_architect/pull/18) - Fix controller bug when using an non-ActiveRecord ORM only within Rails
9
24
  - **2.1.0** - June 20, 2018
10
- - [PR #15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Improved the method symbolize_keys. This method did not work properly for nested objects.
25
+ - [#15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Improved the method symbolize_keys. This method did not work properly for nested objects.
11
26
  - [PR #15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Added the ability to pass `:text_wrap` option within the `:alignment` style
12
27
  - Make axlsx styles higher precendence over Spreadsheet Architect style aliases
13
28
  - Use `prepend` monkey patches in Ruby 2+ to avoid annoying overwrite warnings when using old `define_method` monkey patches
data/README.md CHANGED
@@ -1,92 +1,129 @@
1
1
  # Spreadsheet Architect
2
2
 
3
- <a href='https://travis-ci.org/westonganger/spreadsheet_architect' target='_blank'><img height='24' style='border:0px;height:24px;' src='https://api.travis-ci.org/westonganger/spreadsheet_architect.svg?branch=master' border='0' alt='Build Status' /></a>
4
- <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='24' style='border:0px;height:24px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
3
+ <a href="https://badge.fury.io/rb/spreadsheet_architect" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/spreadsheet_architect.svg" alt="Gem Version"></a>
4
+ <a href='https://travis-ci.org/westonganger/spreadsheet_architect' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://api.travis-ci.org/westonganger/spreadsheet_architect.svg?branch=master' border='0' alt='Build Status' /></a>
5
+ <a href='https://rubygems.org/gems/spreadsheet_architect' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/spreadsheet_architect?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
6
+ <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
5
7
 
6
- Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets easily from ActiveRecord relations, Plain Ruby classes, or predefined data.
8
+ Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets super easily from ActiveRecord relations, plain Ruby objects, or tabular data.
7
9
 
8
10
  Key Features:
9
11
 
10
- - Can generate headers & columns from ActiveRecord column_names or a Class/Model's `spreadsheet_columns` method
11
12
  - Dead simple custom spreadsheets with custom data
12
- - Data Sources: ActiveRecord relations, array of Ruby Objects, or 2D Array Data
13
+ - Data Sources: ActiveRecord relations, array of plain Ruby object instances, or tabular 2D Array Data
13
14
  - Easily style and customize spreadsheets
14
15
  - Create multi sheet spreadsheets
15
16
  - Setting Class/Model or Project specific defaults
16
17
  - Simple to use ActionController renderers for Rails
17
- - Plain Ruby (without Rails) supported
18
+ - Plain Ruby (without Rails) completely supported
18
19
 
19
- Spreadsheet Architect adds the following methods:
20
+ # Install
20
21
  ```ruby
21
- # Rails ActiveRecord Model
22
- Post.order(name: :asc).where(published: true).to_xlsx
23
- Post.order(name: :asc).where(published: true).to_ods
24
- Post.order(name: :asc).where(published: true).to_csv
22
+ gem 'spreadsheet_architect'
23
+ ```
25
24
 
26
- # Plain Ruby Class
27
- Post.to_xlsx(instances: posts_array)
28
- Post.to_ods(instances: posts_array)
29
- Post.to_csv(instances: posts_array)
25
+ # General Usage
26
+
27
+ ### Tabular (Array) Data
30
28
 
31
- # One Time Usage
29
+ ```ruby
32
30
  headers = ['Col 1','Col 2','Col 3']
33
31
  data = [[1,2,3], [4,5,6], [7,8,9]]
34
- SpreadsheetArchitect.to_xlsx(data: data, headers: headers)
35
- SpreadsheetArchitect.to_ods(data: data, headers: headers)
36
- SpreadsheetArchitect.to_csv(data: data, header: false)
32
+ SpreadsheetArchitect.to_xlsx(headers: headers, data: data)
33
+ SpreadsheetArchitect.to_ods(headers: headers, data: data)
34
+ SpreadsheetArchitect.to_csv(headers: headers, data: data)
37
35
  ```
38
36
 
39
- # Install
37
+ ### Rails relation or an array of plain Ruby object instances
38
+
40
39
  ```ruby
41
- # Gemfile
42
- gem 'spreadsheet_architect'
40
+ posts = Post.order(name: :asc).where(published: true)
41
+ # OR
42
+ posts = 10.times.map{|i| Post.new(number: i)}
43
+
44
+ SpreadsheetArchitect.to_xlsx(instances: posts)
45
+ SpreadsheetArchitect.to_ods(instances: posts)
46
+ SpreadsheetArchitect.to_csv(instances: posts)
43
47
  ```
44
48
 
45
- # Basic Class/Model Setup
49
+ **(Optional)** If you would like to add the methods `to_xlsx`, `to_ods`, `to_csv`, `to_axlsx_package`, `to_rodf_spreadsheet` to some class, you can simply include the SpreadsheetArchitect module to whichever classes you choose. A good default strategy is to simply add it to the ApplicationRecord or another parent class to have it available on all appropriate classes. For example:
46
50
 
47
- ### Model
48
51
  ```ruby
49
- class Post < ActiveRecord::Base #activerecord not required
52
+ class ApplicationRecord < ActiveRecord::Base
50
53
  include SpreadsheetArchitect
54
+ end
55
+ ```
56
+
57
+ Then use it on the class or ActiveRecord relations of the class
58
+
59
+ ```ruby
60
+ posts = Post.order(name: :asc).where(published: true)
61
+ posts.to_xlsx
62
+ posts.to_ods
63
+ posts.to_csv
64
+
65
+ # Plain Ruby Objects
66
+ posts_array = 10.times.map{|i| Post.new(number: i)}
67
+ Post.to_xlsx(instances: posts_array)
68
+ Post.to_ods(instances: posts_array)
69
+ Post.to_csv(instances: posts_array)
70
+ ```
71
+
72
+ # Usage with Instances / ActiveRecord Relations
51
73
 
52
- belongs_to :author
53
- belongs_to :category
54
- has_many :tags
74
+ When NOT using the `:data` option, ie. on an AR Relation or using the `:instances` option, Spreadsheet Architect requires an instance method defined on the class to generate the data. It looks for the `spreadsheet_columns` method on the class. If you are using on an ActiveRecord model and that method is not defined, it would fallback to the models `column_names` method (not recommended). If using the `:data` option this is ignored.
75
+
76
+ ```ruby
77
+ class Post
55
78
 
56
- #optional for activerecord classes, defaults to the models column_names
57
79
  def spreadsheet_columns
58
80
 
59
- #[[Label, Method/Statement, Type(optional) to Call on each Instance, Cell Type(optional)]....]
81
+ ### Column format is: [Header, Cell Data / Method (if symbol) to Call on each Instance, (optional) Cell Type]
60
82
  [
61
83
  ['Title', :title],
62
- ['Content', content],
84
+ ['Content', content.strip],
63
85
  ['Author', (author.name if author)],
64
86
  ['Published?', (published ? 'Yes' : 'No')],
65
- ['Published At', :published_at],
87
+ :published_at, # uses the method name as header title Ex. 'Published At'
66
88
  ['# of Views', :number_of_views, :float],
67
89
  ['Rating', :rating],
68
90
  ['Category/Tags', "#{category.name} - #{tags.collect(&:name).join(', ')}"]
69
91
  ]
92
+ end
93
+ ```
70
94
 
71
- # OR if you want to use the method or attribute name as a label it must be a symbol ex. "Title", "Content", "Published"
72
- [:title, :content, :published]
95
+ Alternatively, if `spreadsheet_columns` is passed as an option, this instance method does not need to be defined on the class. If defined on the class then naturally this will override it.
73
96
 
74
- # OR a Combination of Both ex. "Title", "Content", "Author Name", "Published"
75
- [:title, :content, ['Author Name',(author.name rescue nil)], ['# of Views', :number_of_views, :float], :published]
76
- end
77
- end
97
+ ```ruby
98
+ Post.to_xlsx(instances: posts, spreadsheet_columns: Proc.new{|instance|
99
+ [
100
+ ['Title', :title],
101
+ ['Content', instance.content.strip],
102
+ ['Author', (instance.author.name if instance.author)],
103
+ ['Published?', (instance.published ? 'Yes' : 'No')],
104
+ :published_at, # uses the method name as header title Einstance. 'Published At'
105
+ ['# of Views', :number_of_views, :float],
106
+ ['Rating', :rating],
107
+ ['Category/Tags', "#{instance.category.name} - #{instance.tags.collect(&:name).join(', ')}"]
108
+ ]
109
+ })
78
110
  ```
79
111
 
80
- Note: Do not define your labels inside this method if you are going to be using custom headers in the model or project defaults.
112
+ # Sending & Saving Spreadsheets
81
113
 
82
- # Usage
114
+ ### Method 1: Send Data via Rails Controller
83
115
 
84
- ### Method 1: Controller (for Rails)
85
116
  ```ruby
86
117
 
87
118
  class PostsController < ActionController::Base
88
119
  respond_to :html, :xlsx, :ods, :csv
89
120
 
121
+ def index
122
+ @posts = Post.order(published_at: :asc)
123
+
124
+ render xlsx: @posts
125
+ end
126
+
90
127
  # Using respond_with
91
128
  def index
92
129
  @posts = Post.order(published_at: :asc)
@@ -132,116 +169,100 @@ end
132
169
  ```
133
170
 
134
171
  ### Method 2: Save to a file manually
172
+
135
173
  ```ruby
136
- # Ex. with ActiveRecord relation
174
+ ### Ex. with ActiveRecord relation
175
+ file_data = Post.order(published_at: :asc).to_xlsx
137
176
  File.open('path/to/file.xlsx', 'w+b') do |f|
138
- f.write Post.order(published_at: :asc).to_xlsx
177
+ f.write file_data
139
178
  end
179
+
180
+ file_data = Post.order(published_at: :asc).to_ods
140
181
  File.open('path/to/file.ods', 'w+b') do |f|
141
- f.write Post.order(published_at: :asc).to_ods
182
+ f.write file_data
142
183
  end
184
+
185
+ file_data = Post.order(published_at: :asc).to_csv
143
186
  File.open('path/to/file.csv', 'w+b') do |f|
144
- f.write Post.order(published_at: :asc).to_csv
187
+ f.write file_data
145
188
  end
189
+ ```
146
190
 
147
- # Ex. with plain ruby class
148
- File.open('path/to/file.xlsx', 'w+b') do |f|
149
- f.write Post.to_xlsx(instances: posts_array)
150
- end
191
+ # Multi Sheet XLSX Spreadsheets
192
+ ```ruby
193
+ axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data})
194
+ axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data}, package)
151
195
 
152
- # Ex. One time Usage
153
196
  File.open('path/to/file.xlsx', 'w+b') do |f|
154
- headers = ['Col 1','Col 2','Col 3']
155
- data = [[1,2,3], [4,5,6], [7,8,9]]
156
- f.write SpreadsheetArchitect::to_xlsx(data: data, headers: headers)
197
+ f.write axlsx_package.to_stream.read
157
198
  end
158
199
  ```
159
- <br>
160
-
161
- # Methods & Options
162
-
163
200
 
164
- ## SomeClass.to_xlsx
201
+ See this file for more details: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/multi_sheet_test.rb
165
202
 
166
- |Option|Default|Notes|
167
- |---|---|---|
168
- |**spreadsheet_columns**<br>*Array*| This defaults to your models custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Use this option to override the model instances `spreadsheet_columns` method|
169
- |**instances**<br>*Array*| |**Required only for Non-ActiveRecord classes** Array of class/model instances.|
170
- |**headers**<br>*2D Array*|This defaults to your models custom spreadsheet_columns method or `self.column_names.collect(&:titleize)`|Pass `false` to skip the header row.|
171
- |**sheet_name**<br>*String*|The class name||
172
- |**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
173
- |**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
174
- |**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
175
- |**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
176
- |**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
177
- |**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
178
- |**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.|
179
-
180
- <br>
181
-
182
- ## SomeClass.to_ods
183
-
184
- |Option|Default|Notes|
185
- |---|---|---|
186
- |**spreadsheet_columns**<br>*Array*| This defaults to your models custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Use this option to override the model instances `spreadsheet_columns` method|
187
- |**instances**<br>*Array*| |**Required only for Non-ActiveRecord models** Array of class/model instances.|
188
- |**headers**<br>*2D Array*|`self.column_names.collect(&:titleize)`|Pass `false` to skip the header row.|
189
- |**sheet_name**<br>*String*|The class name||
190
- |**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options (values can be changed though)|
191
- |**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options|
192
-
193
- <br>
203
+ ### Multi Sheet ODS Spreadsheets
204
+ ```ruby
205
+ ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data})
206
+ ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data}, spreadsheet)
194
207
 
195
- ## SomeClass.to_csv
208
+ File.open('path/to/file.ods', 'w+b') do |f|
209
+ f.write ods_spreadsheet
210
+ end
211
+ ```
196
212
 
197
- |Option|Default|Notes|
198
- |---|---|---|
199
- |**spreadsheet_columns**<br>*Array*| This defaults to your models custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Use this to option override the model instances `spreadsheet_columns` method|
200
- |**instances**<br>*Array*| |**Required only for Non-ActiveRecord classes** Array of class/model instances.|
201
- |**headers**<br>*2D Array*|`self.column_names.collect(&:titleize)`| Data for the header rows cells. Pass `false` to skip the header row.|
213
+ See this file for more details: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/multi_sheet_test.rb
202
214
 
203
- <br>
215
+ # Methods
204
216
 
205
- ## SpreadsheetArchitect.to_xlsx
217
+ ## `to_xlsx(options={})`
206
218
 
207
219
  |Option|Default|Notes|
208
220
  |---|---|---|
209
- |**data**<br>*Array*| |Data for the non-header row cells. |
210
- |**headers**<br>*2D Array*|`false`|Data for the header row cells. Pass `false` to skip the header row.|
221
+ |**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
222
+ |**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
223
+ |**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
224
+ |**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
211
225
  |**sheet_name**<br>*String*|`Sheet1`||
212
226
  |**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
213
227
  |**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_styles_reference.md)|
214
- |**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
215
- |**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
216
- |**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
217
- |**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb)|
228
+ |**column_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
229
+ |**range_styles**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
230
+ |**merges**<br>*Array*||Merge cells. [See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb). Warning merges cannot overlap eachother, if you attempt to do so Excel will claim your spreadsheet is corrupt and refuse to open your spreadsheet.|
231
+ |**borders**<br>*Array*||[See this example for usage](https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb)|
218
232
  |**column_types**<br>*Array*||Valid types for XLSX are :string, :integer, :float, :boolean, nil = auto determine.|
219
233
  |**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.|
220
-
221
- <br>
222
234
 
223
- ## SpreadsheetArchitect.to_ods
235
+ ## `to_axlsx_spreadsheet(options={}, axlsx_package_to_join=nil)`
236
+ Same options as `to_xlsx`. For more details
237
+
238
+ ## `to_ods(options={})`
224
239
 
225
240
  |Option|Default|Notes|
226
241
  |---|---|---|
227
- |**data**<br>*2D Array*| |Data for the non-header row cells.|
228
- |**headers**<br>*2D Array*|`false`|Data for the header rows cells. Pass `false` to skip the header row.|
242
+ |**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
243
+ |**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
244
+ |**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
245
+ |**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
229
246
  |**sheet_name**<br>*String*|`Sheet1`||
230
247
  |**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options|
231
248
  |**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options|
232
- |**column_types**<br>*Array*||Valid types for ODS are :string, :float, :date, :time, :percent, :currency, nil = auto determine. Due to [RODF issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string |
233
-
234
- <br>
249
+ |**column_types**<br>*Array*||Valid types for ODS are :string, :float :percent, :currency, :date, :time,, nil = auto determine. Due to [RODF Issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string |
235
250
 
236
- ## SpreadsheetArchitect.to_csv
251
+ ## `to_rodf_spreadsheet(options={}, spreadsheet_to_join=nil)`
252
+ Same options as `to_ods`
253
+
254
+ ## `to_csv(options={})`
237
255
 
238
256
  |Option|Default|Notes|
239
257
  |---|---|---|
240
- |**data**<br>*2D Array*| |Data for the non-header row cells.|
241
- |**headers**<br>*2D Array*|`false`|Data for the header rows cells. Pass `false` to skip the header row.|
258
+ |**data**<br>*2D Array*| |Cannot be used with the `:instances` option.<br><br>Tabular data for the non-header row cells. |
259
+ |**instances**<br>*Array*| |Cannot be used with the `:data` option.<br><br>Array of class/model instances to be used as row data. Cannot be used with :data option|
260
+ |**spreadsheet_columns**<br>*Array*| If using the instances option or on a ActiveRecord relation, this defaults to the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If none of those then falls back to `self.column_names` for ActiveRecord models. | Cannot be used with the `:data` option.<br><br>Use this option to override or define the spreadsheet columns. |
261
+ |**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
262
+
242
263
 
264
+ # Change class-wide default method options
243
265
 
244
- # Change model default method options
245
266
  ```ruby
246
267
  class Post
247
268
  include SpreadsheetArchitect
@@ -262,12 +283,13 @@ class Post
262
283
  range_styles: [],
263
284
  merges: [],
264
285
  borders: [],
265
- column_types: []
286
+ column_types: [],
266
287
  }
267
288
  end
268
289
  ```
269
290
 
270
- # Change project wide default method options
291
+ # Change project-wide default method options
292
+
271
293
  ```ruby
272
294
  # config/initializers/spreadsheet_architect.rb
273
295
 
@@ -280,33 +302,31 @@ SpreadsheetArchitect.default_options = {
280
302
  range_styles: [],
281
303
  merges: [],
282
304
  borders: [],
283
- column_types: []
305
+ column_types: [],
284
306
  }
285
307
  ```
286
308
 
287
- # Complex XLSX Example with Styling
288
- See this example: https://github.com/westonganger/spreadsheet_architect/blob/master/examples/complex_xlsx_styling.rb
309
+ # Kitchen Sink Examples with Styling for XLSX and ODS
310
+ See this example: https://github.com/westonganger/spreadsheet_architect/blob/master/test/spreadsheet_architect/kitchen_sink_test.rb
289
311
 
312
+ # Axlsx Style Reference
290
313
 
291
- # Multi Sheet XLSX or ODS spreadsheets
292
- ```ruby
293
- # Returns corresponding spreadsheet libraries object
294
- package = SpreadsheetArchitect.to_axlsx_package({data: data, headers: headers})
295
- SpreadsheetArchitect.to_axlsx_package({data: data, headers: headers}, package) # to combine two sheets to one file
314
+ I have compiled a list of all available style options for axlsx here: https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_style_reference.md
296
315
 
297
- spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({data: data, headers: headers})
298
- SpreadsheetArchitect.to_rodf_spreadsheet({data: data, headers: headers}, spreadsheet) # to combine two sheets to one file
299
- ```
316
+ # Testing / Validating your Spreadsheets
300
317
 
301
- See this example: https://github.com/westonganger/spreadsheet_architect/blob/master/examples/multi_sheet_spreadsheets.rb
318
+ A wise word of advice, when testing your spreadsheets I recommend to use Excel instead of LibreOffice. This is because I have seen through testing, that where LibreOffice seems to just let most incorrect things just slide on through, Excel will not even open the spreadsheet as apparently it is much more strict about the spreadsheet validations. This will help you better identify any incorrect styling or customization issues.
302
319
 
320
+ # Contributing
303
321
 
304
- # Axlsx Style Reference
305
- I have compiled a list of all available style options for axlsx here: https://github.com/westonganger/spreadsheet_architect/blob/master/docs/axlsx_style_reference.md
322
+ We use the `appraisal` gem for testing multiple versions of `axlsx`. Please use the following steps to test using `appraisal`.
306
323
 
324
+ 1. `bundle exec appraisal install`
325
+ 2. `bundle exec appraisal rake test`
307
326
 
308
327
  # Credits
309
- Created by [@westonganger](https://github.com/westonganger)
328
+
329
+ Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
310
330
 
311
331
  For any consulting or contract work please contact me via my company website: [Solid Foundation Web Development](https://solidfoundationwebdev.com)
312
332
 
@@ -3,8 +3,8 @@ require 'csv'
3
3
  module SpreadsheetArchitect
4
4
  module ClassMethods
5
5
  def to_csv(opts={})
6
- opts = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
7
- options = SpreadsheetArchitect::Utils.get_options(opts, self)
6
+ opts = SpreadsheetArchitect::Utils.get_options(opts, self)
7
+ options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
8
8
 
9
9
  CSV.generate do |csv|
10
10
  if options[:headers]
@@ -7,8 +7,8 @@ module SpreadsheetArchitect
7
7
  end
8
8
 
9
9
  def to_rodf_spreadsheet(opts={}, spreadsheet=nil)
10
- opts = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
11
- options = SpreadsheetArchitect::Utils.get_options(opts, self)
10
+ opts = SpreadsheetArchitect::Utils.get_options(opts, self)
11
+ options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
12
12
 
13
13
  if !spreadsheet
14
14
  spreadsheet = RODF::Spreadsheet.new
@@ -10,8 +10,8 @@ module SpreadsheetArchitect
10
10
  end
11
11
 
12
12
  def to_axlsx_package(opts={}, package=nil)
13
- opts = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
14
- options = SpreadsheetArchitect::Utils.get_options(opts, self)
13
+ opts = SpreadsheetArchitect::Utils.get_options(opts, self)
14
+ options = SpreadsheetArchitect::Utils.get_cell_data(opts, self)
15
15
 
16
16
  header_style = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(options[:header_style])
17
17
  row_style = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(options[:row_style])
@@ -93,18 +93,16 @@ module SpreadsheetArchitect
93
93
  end
94
94
 
95
95
  if options[:borders] || options[:column_styles] || options[:range_styles] || options[:merges]
96
- col_names = max_row_length > 675 ? Array('A'..'ZZZ') : Array('A'..'ZZ')
97
96
  num_rows = options[:data].count + (options[:headers] ? options[:headers].count : 0)
98
97
  end
99
98
 
100
99
  if options[:borders]
101
100
  options[:borders].each do |x|
102
101
  if x[:range].is_a?(Hash)
103
- x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows, col_names)
102
+ x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
103
+ else
104
+ SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
104
105
  end
105
-
106
- SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
107
- sheet.add_border x[:range], x[:border_styles]
108
106
  end
109
107
  end
110
108
 
@@ -119,33 +117,29 @@ module SpreadsheetArchitect
119
117
  package.workbook.styles do |s|
120
118
  style = s.add_style row_style.merge(SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(x[:styles]))
121
119
 
122
- if x[:columns].is_a?(Array) || x[:columns].is_a?(Range)
120
+ case x[:columns]
121
+ when Array, Range
123
122
  x[:columns].each do |col|
124
- if col.is_a?(String)
125
- col = col_names.index(col)
126
- end
123
+ SpreadsheetArchitect::Utils::XLSX.verify_column(col, max_row_length)
127
124
 
128
- if col.is_a?(Integer) && col < max_row_length
129
- sheet.col_style(col, style, row_offset: start_row)
125
+ sheet.col_style(col, style, row_offset: start_row)
130
126
 
131
- if h_style
132
- sheet.add_style("#{col_names[col]}1:#{col_names[col]}#{start_row}", h_style)
133
- end
134
- else
135
- raise SpreadsheetArchitect::Exceptions::InvalidColumnError
127
+ if h_style
128
+ sheet.add_style("#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}1:#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}#{start_row}", h_style)
136
129
  end
137
130
  end
138
- elsif x[:columns].is_a?(Integer)
131
+ when Integer, String
139
132
  col = x[:columns]
140
- if col < max_row_length
141
- sheet.col_style(x[:columns], style, row_offset: start_row)
142
133
 
143
- if h_style
144
- sheet.add_style("#{col_names[col]}1:#{col_names[col]}#{start_row}", h_style)
145
- end
146
- else
147
- raise SpreadsheetArchitect::Exceptions::InvalidColumnError
134
+ SpreadsheetArchitect::Utils::XLSX.verify_column(col, max_row_length)
135
+
136
+ sheet.col_style(x[:columns], style, row_offset: start_row)
137
+
138
+ if h_style
139
+ sheet.add_style("#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}1:#{SpreadsheetArchitect::Utils::XLSX::COL_NAMES[col]}#{start_row}", h_style)
148
140
  end
141
+ else
142
+ SpreadsheetArchitect::Utils::XLSX.verify_column(x[:columns], max_row_length)
149
143
  end
150
144
  end
151
145
  end
@@ -156,10 +150,11 @@ module SpreadsheetArchitect
156
150
  styles = SpreadsheetArchitect::Utils::XLSX.convert_styles_to_axlsx(x[:styles])
157
151
 
158
152
  if x[:range].is_a?(Hash)
159
- x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows, col_names)
153
+ x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
154
+ else
155
+ SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
160
156
  end
161
157
 
162
- SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
163
158
  sheet.add_style x[:range], styles
164
159
  end
165
160
  end
@@ -167,10 +162,11 @@ module SpreadsheetArchitect
167
162
  if options[:merges]
168
163
  options[:merges].each do |x|
169
164
  if x[:range].is_a?(Hash)
170
- x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows, col_names)
165
+ x[:range] = SpreadsheetArchitect::Utils::XLSX.range_hash_to_str(x[:range], max_row_length, num_rows)
166
+ else
167
+ SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows)
171
168
  end
172
169
 
173
- SpreadsheetArchitect::Utils::XLSX.verify_range(x[:range], num_rows, col_names)
174
170
  sheet.merge_cells x[:range]
175
171
  end
176
172
  end