datashift 0.16.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +0 -0
- data/Rakefile +1 -20
- data/datashift.thor +125 -0
- data/lib/applications/apache_poi_extensions.rb +21 -52
- data/lib/applications/excel.rb +64 -57
- data/lib/applications/hssf_row_extensions.rb +66 -0
- data/lib/applications/jexcel_file.rb +99 -95
- data/lib/applications/jexcel_file_extensions.rb +76 -83
- data/lib/applications/jruby/word.rb +36 -36
- data/lib/applications/ruby_poi_translations.rb +34 -32
- data/lib/applications/spreadsheet_extensions.rb +21 -19
- data/lib/datashift.rb +49 -59
- data/lib/datashift/binder.rb +217 -0
- data/lib/datashift/column_packer.rb +21 -72
- data/lib/datashift/configuration.rb +317 -0
- data/lib/datashift/context_factory.rb +88 -0
- data/lib/datashift/core_ext/array.rb +15 -0
- data/lib/datashift/core_ext/csv_ext.rb +46 -0
- data/lib/datashift/core_ext/string.rb +49 -0
- data/lib/datashift/core_ext/to_b.rb +11 -0
- data/lib/datashift/delimiters.rb +55 -61
- data/lib/datashift/doc_context.rb +137 -0
- data/lib/datashift/excel_base.rb +93 -81
- data/lib/datashift/exceptions.rb +30 -28
- data/lib/datashift/file_definitions.rb +44 -39
- data/lib/datashift/guards.rb +5 -5
- data/lib/datashift/header.rb +25 -0
- data/lib/datashift/headers.rb +94 -0
- data/lib/datashift/inbound_data/column.rb +44 -0
- data/lib/datashift/inbound_data/lookup_support.rb +33 -0
- data/lib/datashift/inbound_data/method_binding.rb +139 -0
- data/lib/datashift/load_object.rb +37 -12
- data/lib/datashift/logging.rb +54 -27
- data/lib/datashift/mandatory.rb +39 -0
- data/lib/datashift/mapping/data_flow_schema.rb +198 -0
- data/lib/datashift/{model_mapper.rb → mapping/mapper_utils.rb} +30 -10
- data/lib/datashift/model_methods/catalogue.rb +183 -0
- data/lib/datashift/model_methods/collection.rb +140 -0
- data/lib/datashift/model_methods/model_method.rb +162 -0
- data/lib/datashift/model_methods/model_methods_manager.rb +76 -0
- data/lib/datashift/model_methods/operator.rb +62 -0
- data/lib/datashift/node_collection.rb +26 -0
- data/lib/datashift/node_context.rb +68 -0
- data/lib/datashift/populator.rb +308 -282
- data/lib/datashift/progress_monitor.rb +91 -0
- data/lib/datashift/querying.rb +110 -52
- data/lib/datashift/templates/import_export_config.erb +55 -0
- data/lib/datashift/transformation/factory.rb +219 -0
- data/lib/datashift/transformation/remove.rb +44 -0
- data/lib/datashift/version.rb +3 -0
- data/lib/exporters/configuration.rb +84 -0
- data/lib/exporters/csv_exporter.rb +54 -52
- data/lib/exporters/excel_exporter.rb +80 -61
- data/lib/exporters/exporter_base.rb +8 -8
- data/lib/generators/config_generator.rb +218 -0
- data/lib/generators/csv_generator.rb +13 -70
- data/lib/generators/excel_generator.rb +23 -111
- data/lib/generators/generator_base.rb +15 -70
- data/lib/loaders/configuration.rb +90 -0
- data/lib/loaders/csv_loader.rb +63 -101
- data/lib/loaders/excel_loader.rb +71 -156
- data/lib/loaders/failure_data.rb +40 -0
- data/lib/loaders/file_loader.rb +16 -0
- data/lib/loaders/loader_base.rb +82 -410
- data/lib/loaders/loader_factory.rb +42 -0
- data/lib/loaders/paperclip/attachment_loader.rb +157 -140
- data/lib/loaders/paperclip/datashift_paperclip.rb +18 -35
- data/lib/loaders/paperclip/image_loading.rb +40 -35
- data/lib/loaders/reporters/basic_stdout_reporter.rb +40 -0
- data/lib/loaders/reporters/reporter.rb +26 -0
- data/lib/tasks/config.thor +65 -0
- data/{tasks → lib/tasks}/config/seed_fu_product_template.erb +0 -0
- data/{tasks → lib/tasks}/config/tidy_config.txt +0 -0
- data/lib/tasks/export.thor +192 -0
- data/lib/tasks/generate.thor +190 -0
- data/lib/tasks/import.thor +142 -0
- data/lib/{thor → tasks}/paperclip.thor +69 -69
- data/{tasks → lib/tasks/to_convert_to_thor}/db_tasks.rake +20 -20
- data/lib/tasks/tools.thor +109 -0
- data/spec/MissingAttachmentRecords/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/datashift/binder_spec.rb +266 -0
- data/spec/datashift/config_generator_spec.rb +186 -0
- data/spec/datashift/configuration.rb +66 -0
- data/spec/datashift/context_factory_spec.rb +63 -0
- data/spec/datashift/data_flow_schema_spec.rb +150 -0
- data/spec/datashift/datashift_spec.rb +52 -0
- data/spec/datashift/excel_base_spec.rb +57 -0
- data/spec/datashift/excel_spec.rb +188 -0
- data/spec/datashift/failure_data_spec.rb +27 -0
- data/spec/{file_definitions.rb → datashift/file_definitions.rb} +9 -10
- data/spec/datashift/headers_spec.rb +56 -0
- data/spec/datashift/inbound_data_spec.rb +47 -0
- data/spec/datashift/mapper_utils_spec.rb +38 -0
- data/spec/datashift/method_binding_spec.rb +60 -0
- data/spec/datashift/model_method_spec.rb +109 -0
- data/spec/datashift/model_methods_catalogue.rb +111 -0
- data/spec/datashift/model_methods_collection_spec.rb +138 -0
- data/spec/datashift/model_methods_manager_spec.rb +329 -0
- data/spec/datashift/populator_spec.rb +117 -0
- data/spec/datashift/thor_spec.rb +314 -0
- data/spec/datashift/transformation/factory_spec.rb +195 -0
- data/spec/datashift/transformation/transformer_remove_spec.rb +43 -0
- data/spec/dummy/Gemfile +53 -0
- data/spec/dummy/Gemfile.lock +197 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/javascripts/categories.js +2 -0
- data/spec/dummy/app/assets/javascripts/digitals.js +2 -0
- data/spec/dummy/app/assets/javascripts/empties.js +2 -0
- data/spec/dummy/app/assets/javascripts/loader_releases.js +2 -0
- data/spec/dummy/app/assets/javascripts/long_and_complex_table_linked_to_versions.js +2 -0
- data/spec/dummy/app/assets/javascripts/milestones.js +2 -0
- data/spec/dummy/app/assets/javascripts/owners.js +2 -0
- data/spec/dummy/app/assets/javascripts/projects.js +2 -0
- data/spec/dummy/app/assets/javascripts/users.js +2 -0
- data/spec/dummy/app/assets/javascripts/versions.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/categories.css +4 -0
- data/spec/dummy/app/assets/stylesheets/digitals.css +4 -0
- data/spec/dummy/app/assets/stylesheets/empties.css +4 -0
- data/spec/dummy/app/assets/stylesheets/loader_releases.css +4 -0
- data/spec/dummy/app/assets/stylesheets/long_and_complex_table_linked_to_versions.css +4 -0
- data/spec/dummy/app/assets/stylesheets/milestones.css +4 -0
- data/spec/dummy/app/assets/stylesheets/owners.css +4 -0
- data/spec/dummy/app/assets/stylesheets/projects.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/assets/stylesheets/users.css +4 -0
- data/spec/dummy/app/assets/stylesheets/versions.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/categories_controller.rb +58 -0
- data/spec/dummy/app/controllers/digitals_controller.rb +58 -0
- data/spec/dummy/app/controllers/empties_controller.rb +58 -0
- data/spec/dummy/app/controllers/loader_releases_controller.rb +58 -0
- data/spec/dummy/app/controllers/long_and_complex_table_linked_to_versions_controller.rb +58 -0
- data/spec/dummy/app/controllers/milestones_controller.rb +58 -0
- data/spec/dummy/app/controllers/owners_controller.rb +58 -0
- data/spec/dummy/app/controllers/projects_controller.rb +58 -0
- data/spec/dummy/app/controllers/users_controller.rb +58 -0
- data/spec/dummy/app/controllers/versions_controller.rb +58 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/categories_helper.rb +2 -0
- data/spec/dummy/app/helpers/digitals_helper.rb +2 -0
- data/spec/dummy/app/helpers/empties_helper.rb +2 -0
- data/spec/dummy/app/helpers/loader_releases_helper.rb +2 -0
- data/spec/dummy/app/helpers/long_and_complex_table_linked_to_versions_helper.rb +2 -0
- data/spec/dummy/app/helpers/milestones_helper.rb +2 -0
- data/spec/dummy/app/helpers/owners_helper.rb +2 -0
- data/spec/dummy/app/helpers/projects_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/helpers/versions_helper.rb +2 -0
- data/spec/dummy/app/models/category.rb +6 -0
- data/spec/dummy/app/models/digital.rb +22 -0
- data/spec/dummy/app/models/empty.rb +2 -0
- data/spec/dummy/app/models/loader_release.rb +10 -0
- data/spec/dummy/app/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/dummy/app/models/milestone.rb +15 -0
- data/spec/dummy/app/models/owner.rb +13 -0
- data/spec/dummy/app/models/project.rb +53 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/models/version.rb +7 -0
- data/spec/dummy/app/views/categories/_form.html.erb +17 -0
- data/spec/dummy/app/views/categories/edit.html.erb +6 -0
- data/spec/dummy/app/views/categories/index.html.erb +25 -0
- data/spec/dummy/app/views/categories/new.html.erb +5 -0
- data/spec/dummy/app/views/categories/show.html.erb +4 -0
- data/spec/dummy/app/views/digitals/_form.html.erb +17 -0
- data/spec/dummy/app/views/digitals/edit.html.erb +6 -0
- data/spec/dummy/app/views/digitals/index.html.erb +25 -0
- data/spec/dummy/app/views/digitals/new.html.erb +5 -0
- data/spec/dummy/app/views/digitals/show.html.erb +4 -0
- data/spec/dummy/app/views/empties/_form.html.erb +17 -0
- data/spec/dummy/app/views/empties/edit.html.erb +6 -0
- data/spec/dummy/app/views/empties/index.html.erb +25 -0
- data/spec/dummy/app/views/empties/new.html.erb +5 -0
- data/spec/dummy/app/views/empties/show.html.erb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/loader_releases/_form.html.erb +17 -0
- data/spec/dummy/app/views/loader_releases/edit.html.erb +6 -0
- data/spec/dummy/app/views/loader_releases/index.html.erb +25 -0
- data/spec/dummy/app/views/loader_releases/new.html.erb +5 -0
- data/spec/dummy/app/views/loader_releases/show.html.erb +4 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/_form.html.erb +17 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/edit.html.erb +6 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/index.html.erb +25 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/new.html.erb +5 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/show.html.erb +4 -0
- data/spec/dummy/app/views/milestones/_form.html.erb +17 -0
- data/spec/dummy/app/views/milestones/edit.html.erb +6 -0
- data/spec/dummy/app/views/milestones/index.html.erb +25 -0
- data/spec/dummy/app/views/milestones/new.html.erb +5 -0
- data/spec/dummy/app/views/milestones/show.html.erb +4 -0
- data/spec/dummy/app/views/owners/_form.html.erb +17 -0
- data/spec/dummy/app/views/owners/edit.html.erb +6 -0
- data/spec/dummy/app/views/owners/index.html.erb +25 -0
- data/spec/dummy/app/views/owners/new.html.erb +5 -0
- data/spec/dummy/app/views/owners/show.html.erb +4 -0
- data/spec/dummy/app/views/projects/_form.html.erb +17 -0
- data/spec/dummy/app/views/projects/edit.html.erb +6 -0
- data/spec/dummy/app/views/projects/index.html.erb +25 -0
- data/spec/dummy/app/views/projects/new.html.erb +5 -0
- data/spec/dummy/app/views/projects/show.html.erb +4 -0
- data/spec/dummy/app/views/users/_form.html.erb +17 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +25 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +4 -0
- data/spec/dummy/app/views/versions/_form.html.erb +17 -0
- data/spec/dummy/app/views/versions/edit.html.erb +6 -0
- data/spec/dummy/app/views/versions/index.html.erb +25 -0
- data/spec/dummy/app/views/versions/new.html.erb +5 -0
- data/spec/dummy/app/views/versions/show.html.erb +4 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/bin/spring +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +3 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +76 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20110803201325_create_test_bed.rb +98 -0
- data/spec/dummy/db/migrate/20121009161700_add_digitals.rb +24 -0
- data/spec/dummy/db/migrate/20161005123106_create_digitals.rb +8 -0
- data/spec/dummy/db/migrate/20161005123106_create_long_and_complex_table_linked_to_versions.rb +8 -0
- data/spec/dummy/db/migrate/20161005123107_create_loader_releases.rb +8 -0
- data/spec/dummy/db/migrate/20161005123108_create_owners.rb +8 -0
- data/spec/dummy/db/migrate/20161005123109_create_empties.rb +8 -0
- data/spec/dummy/db/migrate/20161005123110_create_projects.rb +8 -0
- data/spec/dummy/db/migrate/20161005123111_create_users.rb +8 -0
- data/spec/dummy/db/migrate/20161005123111_create_versions.rb +8 -0
- data/spec/dummy/db/migrate/20161005123112_create_milestones.rb +8 -0
- data/spec/dummy/db/migrate/20161005123113_create_categories.rb +8 -0
- data/spec/dummy/db/schema.rb +93 -0
- data/spec/dummy/db/seeds.rb +9 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +69 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/sandbox_example.thor +4 -0
- data/spec/dummy/test/controllers/categories_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/digitals_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/empties_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/loader_releases_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/long_and_complex_table_linked_to_versions_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/milestones_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/owners_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/projects_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/users_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/versions_controller_test.rb +49 -0
- data/spec/dummy/test/factories/categories.rb +5 -0
- data/spec/dummy/test/factories/digitals.rb +5 -0
- data/spec/dummy/test/factories/empties.rb +5 -0
- data/spec/dummy/test/factories/loader_releases.rb +5 -0
- data/spec/dummy/test/factories/long_and_complex_table_linked_to_versions.rb +5 -0
- data/spec/dummy/test/factories/milestones.rb +5 -0
- data/spec/dummy/test/factories/owners.rb +5 -0
- data/spec/dummy/test/factories/projects.rb +5 -0
- data/spec/dummy/test/factories/users.rb +5 -0
- data/spec/dummy/test/factories/versions.rb +5 -0
- data/spec/dummy/test/models/category_test.rb +7 -0
- data/spec/dummy/test/models/digital_test.rb +7 -0
- data/spec/dummy/test/models/empty_test.rb +7 -0
- data/spec/dummy/test/models/loader_release_test.rb +7 -0
- data/spec/dummy/test/models/long_and_complex_table_linked_to_version_test.rb +7 -0
- data/spec/dummy/test/models/milestone_test.rb +7 -0
- data/spec/dummy/test/models/owner_test.rb +7 -0
- data/spec/dummy/test/models/project_test.rb +7 -0
- data/spec/dummy/test/models/user_test.rb +7 -0
- data/spec/dummy/test/models/version_test.rb +7 -0
- data/spec/dummy/test/test_helper.rb +10 -0
- data/spec/exporters/csv_exporter_spec.rb +240 -0
- data/spec/exporters/csv_generator_spec.rb +139 -0
- data/spec/exporters/excel_exporter_spec.rb +193 -0
- data/spec/exporters/excel_generator_spec.rb +181 -0
- data/spec/exporters/generator_base_spec.rb +45 -0
- data/spec/factories/categories.rb +7 -0
- data/spec/factories/factories.rb +18 -0
- data/spec/factories/milestone.rb +16 -0
- data/spec/factories/projects.rb +41 -0
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/ProjectConfiguration.yml +18 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xlsx +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/config/database.yml +28 -0
- data/spec/fixtures/csv/BadAssociationName.csv +6 -0
- data/spec/fixtures/csv/DemoNegativeTesting.csv +6 -0
- data/spec/fixtures/csv/ProjectsMultiCategories.csv +5 -0
- data/spec/fixtures/csv/ProjectsMultiCategoriesHeaderLookup.csv +5 -0
- data/spec/fixtures/csv/ProjectsSingleCategories.csv +5 -0
- data/spec/fixtures/csv/SimpleProjects.csv +4 -0
- data/spec/fixtures/db/migrate/20110803201325_create_test_bed.rb +98 -0
- data/spec/fixtures/db/migrate/20121009161700_add_digitals.rb +24 -0
- data/spec/fixtures/db/seeds.rb +9 -0
- data/spec/fixtures/images/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/fixtures/images/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/fixtures/images/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/fixtures/images/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/fixtures/load_datashift.thor +3 -0
- data/spec/fixtures/models/category.rb +6 -0
- data/spec/fixtures/models/digital.rb +22 -0
- data/spec/fixtures/models/empty.rb +2 -0
- data/spec/fixtures/models/loader_release.rb +10 -0
- data/spec/fixtures/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/fixtures/models/milestone.rb +15 -0
- data/spec/fixtures/models/owner.rb +13 -0
- data/spec/fixtures/models/project.rb +53 -0
- data/spec/fixtures/models/user.rb +5 -0
- data/spec/fixtures/models/version.rb +7 -0
- data/spec/fixtures/results/exp_project_assoc_headers.xls +0 -0
- data/spec/fixtures/results/exp_project_collection_spec.csv +2 -0
- data/spec/fixtures/results/exp_project_export.xls +0 -0
- data/spec/fixtures/results/exp_project_first_export.xls +0 -0
- data/spec/fixtures/results/exp_project_plus_assoc.xls +0 -0
- data/spec/fixtures/results/exp_project_plus_assoc_export_spec.csv +9 -0
- data/spec/fixtures/results/gen_project_plus_assoc_template.xls +0 -0
- data/spec/fixtures/results/gen_project_plus_some_assoc_template.xls +0 -0
- data/spec/fixtures/results/gen_project_template.xls +0 -0
- data/spec/fixtures/results/project_and_assoc_in_hash_export.xls +0 -0
- data/spec/fixtures/results/project_and_assoc_in_json_export.csv +9 -0
- data/spec/fixtures/results/project_and_assoc_in_json_export.xls +0 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_,.csv +2 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_/302/243.csv +2 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_/302/247.csv +2 -0
- data/spec/fixtures/results/project_plus_assoc_template.csv +1 -0
- data/spec/fixtures/results/project_plus_some_assoc_template.csv +1 -0
- data/spec/fixtures/results/project_remove_export_spec.csv +2 -0
- data/spec/fixtures/results/project_template.csv +1 -0
- data/spec/fixtures/results/project_with_methods_export_spec.csv +2 -0
- data/spec/fixtures/results/thor_spec_gen_project.csv +1 -0
- data/spec/fixtures/sandbox_example.thor +4 -0
- data/spec/fixtures/simple_export_spec.xls +0 -0
- data/spec/fixtures/simple_template_spec.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +7 -0
- data/spec/loaders/csv_loader_spec.rb +206 -0
- data/spec/loaders/data_flow_excel_loader_spec.rb +290 -0
- data/spec/loaders/excel_loader_failures_spec.rb +67 -0
- data/spec/loaders/excel_loader_spec.rb +294 -0
- data/spec/loaders/loader_base_spec.rb +29 -0
- data/spec/loaders/paperclip_loader_spec.rb +106 -0
- data/spec/log/datashift.log +14930 -0
- data/spec/private/digitals/1/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/private/digitals/2/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/private/digitals/3/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/private/digitals/4/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/spec_helper.rb +26 -230
- data/spec/support/clear_and_manage_contexts.rb +25 -0
- data/spec/support/database_cleaner.rb +32 -0
- data/spec/support/datashift_test_helpers.rb +153 -0
- data/spec/support/files_paths_helper.rb +13 -0
- data/spec/support/fixtures/results/mapping_template.yaml +15 -0
- data/spec/support/sandbox.rb +136 -0
- metadata +804 -85
- data/README.markdown +0 -274
- data/README.rdoc +0 -19
- data/VERSION +0 -1
- data/datashift.gemspec +0 -48
- data/lib/applications/jruby/old_pre_proxy_jexcel_file.rb +0 -437
- data/lib/datashift/data_transforms.rb +0 -83
- data/lib/datashift/mapping_file_definitions.rb +0 -88
- data/lib/datashift/mapping_service.rb +0 -91
- data/lib/datashift/method_detail.rb +0 -165
- data/lib/datashift/method_details_manager.rb +0 -95
- data/lib/datashift/method_dictionary.rb +0 -281
- data/lib/datashift/method_mapper.rb +0 -174
- data/lib/datashift/thor_base.rb +0 -38
- data/lib/generators/mapping_generator.rb +0 -112
- data/lib/helpers/core_ext/csv_file.rb +0 -33
- data/lib/helpers/core_ext/to_b.rb +0 -24
- data/lib/loaders/reporter.rb +0 -58
- data/lib/thor/export.thor +0 -175
- data/lib/thor/generate.thor +0 -191
- data/lib/thor/import.thor +0 -110
- data/lib/thor/mapping.thor +0 -65
- data/lib/thor/tools.thor +0 -84
- data/spec/Gemfile +0 -31
- data/spec/Gemfile.lock +0 -134
- data/spec/csv_exporter_spec.rb +0 -144
- data/spec/csv_generator_spec.rb +0 -159
- data/spec/csv_loader_spec.rb +0 -212
- data/spec/datashift_spec.rb +0 -55
- data/spec/excel_exporter_spec.rb +0 -199
- data/spec/excel_generator_spec.rb +0 -203
- data/spec/excel_loader_spec.rb +0 -237
- data/spec/excel_spec.rb +0 -203
- data/spec/loader_base_spec.rb +0 -166
- data/spec/mapping_spec.rb +0 -117
- data/spec/method_dictionary_spec.rb +0 -300
- data/spec/method_mapper_spec.rb +0 -100
- data/spec/model_mapper_spec.rb +0 -41
- data/spec/paperclip_loader_spec.rb +0 -92
- data/spec/populator_spec.rb +0 -128
- data/spec/thor_spec.rb +0 -90
- data/tasks/file_tasks.rake +0 -37
- data/tasks/word_to_seedfu.rake +0 -167
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
# Copyright:: Autotelik Media Ltd
|
|
2
2
|
# Author :: Tom Statter
|
|
3
3
|
# Date :: July 2010
|
|
4
|
-
# License::
|
|
4
|
+
# License::
|
|
5
5
|
#
|
|
6
|
-
# A wrapper around creating and directly manipulating Excel files.
|
|
6
|
+
# A wrapper around creating and directly manipulating Excel files.
|
|
7
7
|
#
|
|
8
8
|
# i.e Create and populate XSL files
|
|
9
|
-
#
|
|
9
|
+
#
|
|
10
10
|
# jar added to class path in manifest - 'poi-3.5-beta4-20081128.jar'
|
|
11
11
|
#
|
|
12
|
-
if
|
|
13
|
-
|
|
12
|
+
if DataShift::Guards.jruby?
|
|
13
|
+
|
|
14
14
|
require 'java'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
require 'poi-3.7-20101029.jar'
|
|
16
|
+
|
|
17
|
+
require_relative 'ruby_poi_translations'
|
|
18
|
+
|
|
19
19
|
class JExcelFile
|
|
20
|
-
|
|
21
|
-
include ExcelBase
|
|
22
|
-
|
|
20
|
+
|
|
23
21
|
include RubyPoiTranslations
|
|
24
22
|
extend RubyPoiTranslations
|
|
25
|
-
|
|
23
|
+
|
|
26
24
|
include Enumerable
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
|
|
26
|
+
java_import 'org.apache.poi.hssf.util.HSSFColor'
|
|
29
27
|
java_import 'org.apache.poi.poifs.filesystem.POIFSFileSystem'
|
|
30
28
|
|
|
31
29
|
java_import 'org.apache.poi.hssf.usermodel.HSSFCell'
|
|
@@ -36,73 +34,73 @@ if(DataShift::Guards::jruby?)
|
|
|
36
34
|
java_import 'org.apache.poi.hssf.usermodel.HSSFRichTextString'
|
|
37
35
|
|
|
38
36
|
attr_accessor :workbook, :row, :date_style
|
|
39
|
-
attr_reader
|
|
37
|
+
attr_reader :sheet, :current_sheet_index
|
|
40
38
|
|
|
41
39
|
# NOTE: this is the POI 3.7 HSSF maximum rows
|
|
42
40
|
@@maxrows = 65535
|
|
43
41
|
|
|
44
42
|
def self.maxrows
|
|
45
|
-
|
|
43
|
+
@@maxrows
|
|
46
44
|
end
|
|
47
|
-
|
|
45
|
+
|
|
48
46
|
def self.date_format
|
|
49
|
-
HSSFDataFormat.getBuiltinFormat(
|
|
47
|
+
HSSFDataFormat.getBuiltinFormat('m/d/yy h:mm')
|
|
50
48
|
end
|
|
51
|
-
|
|
52
|
-
def self.open(
|
|
53
|
-
HSSFWorkbook.new(FileInputStream.new(
|
|
49
|
+
|
|
50
|
+
def self.open(file_name)
|
|
51
|
+
HSSFWorkbook.new(FileInputStream.new(file_name))
|
|
54
52
|
end
|
|
55
|
-
|
|
53
|
+
|
|
56
54
|
# NOTES :
|
|
57
55
|
# The HSSFWorkbook uses 0 based indexes
|
|
58
|
-
|
|
59
|
-
def initialize
|
|
56
|
+
|
|
57
|
+
def initialize
|
|
60
58
|
@workbook = HSSFWorkbook.new
|
|
61
|
-
|
|
59
|
+
|
|
62
60
|
@sheet = nil
|
|
63
61
|
@current_sheet_index = 0
|
|
64
|
-
|
|
62
|
+
|
|
65
63
|
# The @patriarchs hash is a workaround because HSSFSheet.getDrawingPatriarch()
|
|
66
64
|
# causes a lot of issues (if it doesn't throw an exception!)
|
|
67
|
-
@patriarchs =
|
|
68
|
-
|
|
65
|
+
@patriarchs = {}
|
|
66
|
+
|
|
69
67
|
@date_style = nil
|
|
70
68
|
end
|
|
71
|
-
|
|
72
|
-
def open(
|
|
73
|
-
@workbook = JExcelFile.open(
|
|
74
|
-
|
|
69
|
+
|
|
70
|
+
def open(file_name)
|
|
71
|
+
@workbook = JExcelFile.open(file_name)
|
|
72
|
+
|
|
75
73
|
@date_style = @workbook.createCellStyle
|
|
76
|
-
@date_style.setDataFormat( JExcelFile
|
|
77
|
-
|
|
74
|
+
@date_style.setDataFormat( JExcelFile.date_format )
|
|
75
|
+
|
|
78
76
|
activate_sheet(0)
|
|
79
77
|
@workbook
|
|
80
78
|
end
|
|
81
|
-
|
|
82
|
-
# Create and return a new worksheet.
|
|
79
|
+
|
|
80
|
+
# Create and return a new worksheet.
|
|
83
81
|
# Not set to the active worksheet
|
|
84
|
-
|
|
82
|
+
|
|
85
83
|
def create_worksheet( options = {} )
|
|
86
84
|
sheet_name = options[:name]
|
|
87
|
-
|
|
88
|
-
@workbook = HSSFWorkbook.new
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
|
|
86
|
+
@workbook = HSSFWorkbook.new if @workbook.nil?
|
|
87
|
+
|
|
88
|
+
if sheet_name
|
|
89
|
+
|
|
90
|
+
name = sanitize_sheet_name( sheet_name )
|
|
91
|
+
|
|
92
|
+
return create_sheet_and_set_styles( name ) if @workbook.getSheetIndex(name) < 0 # Check sheet doesn't already exist
|
|
93
|
+
|
|
94
|
+
activate_sheet(name)
|
|
95
|
+
|
|
96
|
+
else
|
|
91
97
|
i = 0
|
|
98
|
+
# there is no hard limit to no of sheets in Excel but at some point you will run out of memory!
|
|
92
99
|
begin
|
|
93
100
|
sheet_name = "Worksheet#{i += 1}"
|
|
94
|
-
end while(@workbook.getSheetIndex(sheet_name) >= 0)
|
|
95
|
-
|
|
96
|
-
return create_sheet_and_set_styles( sheet_name )
|
|
97
|
-
else
|
|
98
|
-
|
|
99
|
-
name = sanitize_sheet_name( sheet_name )
|
|
101
|
+
end while(@workbook.getSheetIndex(sheet_name) >= 0)
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
return create_sheet_and_set_styles( name )
|
|
103
|
-
else
|
|
104
|
-
activate_sheet(name)
|
|
105
|
-
end
|
|
103
|
+
return create_sheet_and_set_styles( sheet_name )
|
|
106
104
|
end
|
|
107
105
|
end
|
|
108
106
|
|
|
@@ -110,11 +108,11 @@ if(DataShift::Guards::jruby?)
|
|
|
110
108
|
# If no such sheet return current sheet
|
|
111
109
|
def activate_sheet(term)
|
|
112
110
|
|
|
113
|
-
if
|
|
111
|
+
if @workbook
|
|
114
112
|
x = term.is_a?(String) ? @workbook.getSheetIndex(term.to_java(java.lang.String)) : term
|
|
115
113
|
@sheet = worksheet(x)
|
|
116
|
-
|
|
117
|
-
if
|
|
114
|
+
|
|
115
|
+
if @sheet
|
|
118
116
|
@current_sheet_index = x
|
|
119
117
|
@workbook.setActiveSheet(@current_sheet_index)
|
|
120
118
|
@sheet = @workbook.getSheetAt(@current_sheet_index)
|
|
@@ -125,14 +123,14 @@ if(DataShift::Guards::jruby?)
|
|
|
125
123
|
end
|
|
126
124
|
|
|
127
125
|
# Return a sheet by index
|
|
128
|
-
def worksheet( index )
|
|
129
|
-
if
|
|
126
|
+
def worksheet( index )
|
|
127
|
+
if @workbook
|
|
130
128
|
x = index.is_a?(String) ? @workbook.getSheetIndex(index.to_java(java.lang.String)) : index
|
|
131
|
-
return @workbook.getSheetAt(x)
|
|
129
|
+
return @workbook.getSheetAt(x)
|
|
132
130
|
end
|
|
133
131
|
nil
|
|
134
132
|
end
|
|
135
|
-
|
|
133
|
+
|
|
136
134
|
def worksheets
|
|
137
135
|
(0...@workbook.getNumberOfSheets).collect { |i| @workbook.getSheetAt(i) }
|
|
138
136
|
end
|
|
@@ -140,89 +138,95 @@ if(DataShift::Guards::jruby?)
|
|
|
140
138
|
# Create new row (indexing in line with POI usage, start 0)
|
|
141
139
|
def create_row(index)
|
|
142
140
|
return nil if @sheet.nil?
|
|
143
|
-
raise
|
|
141
|
+
raise 'BAD INDEX: Row indexing starts at 0' if index < 0
|
|
144
142
|
@row = @sheet.createRow(index)
|
|
145
143
|
@row
|
|
146
144
|
end
|
|
147
|
-
|
|
145
|
+
|
|
148
146
|
def num_rows
|
|
149
147
|
@sheet.getPhysicalNumberOfRows
|
|
150
148
|
end
|
|
151
149
|
|
|
152
150
|
# Process each row. Row type is org.apache.poi.hssf.usermodel.HSSFRow
|
|
153
|
-
|
|
151
|
+
|
|
154
152
|
# Currently ignores skip argument - TODO - this is how spreadsheet gem works
|
|
155
|
-
# #each iterates over all used Rows (from the first used Row until
|
|
156
|
-
#
|
|
157
|
-
#
|
|
153
|
+
# #each iterates over all used Rows (from the first used Row until
|
|
154
|
+
# but omitting the first unused Row, see also #dimensions)
|
|
155
|
+
# If the argument skip is given,
|
|
156
|
+
# #each iterates from that row until but omitting the first unused Row,
|
|
157
|
+
# effectively skipping the first skip Rows from the top of the Worksheet.
|
|
158
158
|
|
|
159
|
-
def each(
|
|
159
|
+
def each(_skip = nil, &block)
|
|
160
160
|
@sheet.rowIterator.each(&block)
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
def row( index )
|
|
164
164
|
@sheet.getRow(index) || create_row(index)
|
|
165
165
|
end
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
# Get the enriched value of the Cell at row, column.
|
|
168
|
-
def cell(row, column)
|
|
168
|
+
def cell(row, column)
|
|
169
169
|
row = row(row)
|
|
170
|
-
cell_value( row.get_or_create_cell( column )
|
|
170
|
+
cell_value( row.get_or_create_cell( column ) )
|
|
171
171
|
end
|
|
172
172
|
|
|
173
|
-
# Get the enriched value of the Cell at row, column.
|
|
174
|
-
def [](row, column)
|
|
175
|
-
cell(row, column)
|
|
173
|
+
# Get the enriched value of the Cell at row, column.
|
|
174
|
+
def [](row, column)
|
|
175
|
+
cell(row, column)
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
def []=(row, column, value)
|
|
179
179
|
set_cell(row, column, value)
|
|
180
180
|
end
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
def set_cell(row, column, value)
|
|
183
183
|
@row = row(row)
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
@row[column] = value
|
|
186
186
|
end
|
|
187
|
-
|
|
188
|
-
def
|
|
189
|
-
|
|
187
|
+
|
|
188
|
+
def sanitize_sheet_name( name )
|
|
189
|
+
name.gsub(/[\[\]:\*\/\\\?]/, '')
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def write( file_name = nil )
|
|
193
|
+
file = file_name.nil? ? @filepath : file_name
|
|
190
194
|
out = FileOutputStream.new(file)
|
|
191
195
|
@workbook.write(out) unless @workbook.nil?
|
|
192
196
|
out.close
|
|
193
197
|
end
|
|
194
198
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
def save_to_text(
|
|
198
|
-
File.open(
|
|
199
|
+
alias save write
|
|
200
|
+
|
|
201
|
+
def save_to_text( file_name )
|
|
202
|
+
File.open( file_name, 'w') { |f| f.write(to_s) }
|
|
199
203
|
end
|
|
200
204
|
|
|
201
205
|
def to_s
|
|
202
206
|
outs = ByteArrayOutputStream.new
|
|
203
|
-
@workbook.write(outs)
|
|
204
|
-
outs.close
|
|
207
|
+
@workbook.write(outs)
|
|
208
|
+
outs.close
|
|
205
209
|
String.from_java_bytes(outs.toByteArray)
|
|
206
210
|
end
|
|
207
|
-
|
|
211
|
+
|
|
208
212
|
private
|
|
209
|
-
|
|
213
|
+
|
|
210
214
|
def create_sheet_and_set_styles( sheet_name )
|
|
211
|
-
|
|
215
|
+
|
|
212
216
|
name = sanitize_sheet_name(sheet_name)
|
|
213
|
-
|
|
217
|
+
|
|
214
218
|
@sheet = @workbook.createSheet( name )
|
|
215
219
|
|
|
216
|
-
@patriarchs.store(name, @sheet.createDrawingPatriarch
|
|
217
|
-
|
|
220
|
+
@patriarchs.store(name, @sheet.createDrawingPatriarch)
|
|
221
|
+
|
|
218
222
|
@date_style = @workbook.createCellStyle
|
|
219
|
-
@date_style.setDataFormat( JExcelFile
|
|
223
|
+
@date_style.setDataFormat( JExcelFile.date_format )
|
|
220
224
|
@sheet
|
|
221
225
|
end
|
|
222
|
-
|
|
226
|
+
|
|
223
227
|
end
|
|
224
|
-
|
|
228
|
+
|
|
225
229
|
require 'jexcel_file_extensions'
|
|
226
230
|
require 'apache_poi_extensions'
|
|
227
|
-
|
|
228
|
-
end
|
|
231
|
+
|
|
232
|
+
end
|
|
@@ -1,143 +1,136 @@
|
|
|
1
1
|
# Copyright:: Autotelik Media Ltd
|
|
2
2
|
# Author :: Tom Statter
|
|
3
3
|
# Date :: July 2010
|
|
4
|
-
# License::
|
|
4
|
+
# License::
|
|
5
5
|
#
|
|
6
|
-
# Details:: A helper module providing shortcuts for manipulating Excel files.
|
|
7
|
-
#
|
|
6
|
+
# Details:: A helper module providing shortcuts for manipulating Excel files.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
if DataShift::Guards.jruby?
|
|
8
10
|
|
|
9
|
-
if(DataShift::Guards::jruby?)
|
|
10
|
-
|
|
11
11
|
JExcelFile.class_eval do
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
java_import 'org.apache.poi.hssf.util.HSSFColor'
|
|
13
|
+
|
|
15
14
|
# Return the current active sheet
|
|
16
15
|
# If term supplied find sheet and set active
|
|
17
|
-
#
|
|
16
|
+
#
|
|
18
17
|
def active_worksheet(term = nil)
|
|
19
|
-
if
|
|
18
|
+
if term.nil?
|
|
20
19
|
@sheet ||= @workbook.getSheetAt(@current_sheet_index)
|
|
21
|
-
else
|
|
20
|
+
else
|
|
22
21
|
activate_sheet(term)
|
|
23
|
-
end if
|
|
22
|
+
end if @workbook
|
|
24
23
|
@sheet
|
|
25
24
|
end
|
|
26
|
-
|
|
27
|
-
# Populate a row of cells with data in an array
|
|
25
|
+
|
|
26
|
+
# Populate a row of cells with data in an array
|
|
28
27
|
# where the co-ordinates relate to row/column start position
|
|
29
|
-
#
|
|
28
|
+
#
|
|
30
29
|
def set_row( row, col, data, sheet_num = nil)
|
|
31
|
-
|
|
30
|
+
|
|
32
31
|
sheet(sheet_num)
|
|
33
|
-
|
|
32
|
+
|
|
34
33
|
create_row(row)
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
column = col
|
|
37
36
|
data.each do |datum|
|
|
38
37
|
set_cell(row, column, datum)
|
|
39
38
|
column += 1
|
|
40
39
|
end
|
|
41
40
|
end
|
|
42
|
-
|
|
43
|
-
def headers=( headers )
|
|
44
|
-
headers.each_with_index do |header, column|
|
|
45
|
-
self[0, column] = (header || "")
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
41
|
+
|
|
49
42
|
# Convert array into a header row
|
|
50
43
|
def set_headers(headers, apply_style = nil)
|
|
51
44
|
create_row(0)
|
|
52
45
|
return if headers.empty?
|
|
53
|
-
|
|
54
|
-
style = apply_style || header_style()
|
|
55
46
|
|
|
56
|
-
|
|
47
|
+
style = apply_style || header_style
|
|
48
|
+
|
|
49
|
+
headers.sources.each_with_index do |datum, i|
|
|
57
50
|
c = @row.createCell(i, poi_cell_type(datum))
|
|
58
51
|
c.setCellValue(datum)
|
|
59
52
|
c.setCellStyle(style)
|
|
60
53
|
end
|
|
61
54
|
end
|
|
62
|
-
|
|
55
|
+
|
|
63
56
|
attr_writer :header_background_colour
|
|
64
|
-
|
|
57
|
+
|
|
65
58
|
def header_background_colour
|
|
66
|
-
@header_background_colour ||= org.apache.poi.hssf.util.HSSFColor::LIGHT_CORNFLOWER_BLUE.index
|
|
59
|
+
@header_background_colour ||= org.apache.poi.hssf.util.HSSFColor::LIGHT_CORNFLOWER_BLUE.index
|
|
67
60
|
end
|
|
68
|
-
|
|
61
|
+
|
|
69
62
|
def header_style
|
|
70
63
|
return @header_style if @header_style
|
|
71
|
-
@header_style = @workbook.createCellStyle
|
|
64
|
+
@header_style = @workbook.createCellStyle
|
|
72
65
|
@header_style.setBorderTop(6) # double lines border
|
|
73
66
|
@header_style.setBorderBottom(1) # single line border
|
|
74
67
|
@header_style.setFillBackgroundColor(header_background_colour)
|
|
75
|
-
|
|
68
|
+
|
|
76
69
|
@header_style
|
|
77
70
|
end
|
|
78
|
-
|
|
71
|
+
|
|
79
72
|
def add_comment( cell, text )
|
|
80
|
-
raise
|
|
73
|
+
raise 'Please supply valid HSSFCell' unless cell.respond_to?('setCellComment')
|
|
81
74
|
return if @sheet.nil?
|
|
82
75
|
|
|
83
|
-
patriarch = @patriarchs[@sheet.getSheetName
|
|
76
|
+
patriarch = @patriarchs[@sheet.getSheetName]
|
|
84
77
|
|
|
85
|
-
anchor = HSSFClientAnchor.new(100, 50, 100, 50, cell.getColumnIndex
|
|
78
|
+
anchor = HSSFClientAnchor.new(100, 50, 100, 50, cell.getColumnIndex, cell.getRowIndex, cell.getColumnIndex + 3, cell.getRowIndex + 4)
|
|
86
79
|
comment = patriarch.createCellComment(anchor)
|
|
87
80
|
|
|
88
81
|
comment_text = HSSFRichTextString.new(text)
|
|
89
82
|
comment.setString(comment_text)
|
|
90
|
-
comment.setAuthor(
|
|
83
|
+
comment.setAuthor('Mapping')
|
|
91
84
|
|
|
92
85
|
cell.setCellComment(comment)
|
|
93
86
|
end
|
|
94
|
-
|
|
87
|
+
|
|
95
88
|
# Get a percentage style
|
|
96
|
-
def getPercentStyle
|
|
97
|
-
if
|
|
98
|
-
@percentCellStyle = @workbook.createCellStyle
|
|
99
|
-
@percentCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(
|
|
89
|
+
def getPercentStyle
|
|
90
|
+
if @percentCellStyle.nil? && @workbook
|
|
91
|
+
@percentCellStyle = @workbook.createCellStyle
|
|
92
|
+
@percentCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat('0.00%'))
|
|
100
93
|
end
|
|
101
|
-
|
|
94
|
+
@percentCellStyle
|
|
102
95
|
end
|
|
103
96
|
|
|
104
97
|
# Auto size either the given column index or all columns
|
|
105
98
|
def autosize(column = nil)
|
|
106
99
|
return if @sheet.nil?
|
|
107
|
-
if
|
|
100
|
+
if column.is_a? Integer
|
|
108
101
|
@sheet.autoSizeColumn(column)
|
|
109
102
|
else
|
|
110
|
-
@sheet.getRow(0).cellIterator.each{|c| @sheet.autoSizeColumn(c.getColumnIndex)}
|
|
103
|
+
@sheet.getRow(0).cellIterator.each { |c| @sheet.autoSizeColumn(c.getColumnIndex) }
|
|
111
104
|
end
|
|
112
105
|
end
|
|
113
|
-
|
|
114
|
-
def create_freeze_pane(row=1, column=0)
|
|
106
|
+
|
|
107
|
+
def create_freeze_pane(row = 1, column = 0)
|
|
115
108
|
return if @sheet.nil?
|
|
116
109
|
@sheet.createFreezePane(row, column)
|
|
117
110
|
end
|
|
118
111
|
|
|
119
|
-
|
|
120
112
|
# Use execute to run sql query provided
|
|
121
113
|
# and write to a csv file (path required)
|
|
122
114
|
# header row is optional but default is on
|
|
123
115
|
# Auto mapping of specified columns is optional
|
|
124
116
|
# @mappings is a hash{column => map} of columns to a map{old_value => new_value}
|
|
125
|
-
def results_to_sheet( results, sheet, mappings=nil, header=true)
|
|
117
|
+
def results_to_sheet( results, sheet, mappings = nil, header = true)
|
|
126
118
|
numrows = results.length
|
|
127
119
|
sheet_name = sheet
|
|
128
120
|
|
|
129
|
-
if
|
|
121
|
+
if numrows == 0
|
|
130
122
|
log :info, "WARNING - results are empty nothing written to sheet: #{sheet}"
|
|
131
123
|
return
|
|
132
124
|
end
|
|
133
125
|
|
|
134
|
-
#Check if we need to split the results into seperate sheets
|
|
135
|
-
if
|
|
126
|
+
# Check if we need to split the results into seperate sheets
|
|
127
|
+
if numrows > @@maxrows
|
|
136
128
|
startrow = 0
|
|
137
|
-
while
|
|
129
|
+
while numrows > 0
|
|
138
130
|
# Split the results and write to a new sheet
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
slice_at = @@maxrows > numrows ? numrows : @@maxrows
|
|
132
|
+
next_results = results.slice(startrow, slice_at)
|
|
133
|
+
results_to_sheet(next_results, sheet_name.to_s, mappings, header) if next_results
|
|
141
134
|
|
|
142
135
|
# Increase counters
|
|
143
136
|
numrows -= next_results.length
|
|
@@ -147,43 +140,43 @@ if(DataShift::Guards::jruby?)
|
|
|
147
140
|
else
|
|
148
141
|
log :info, "Writting #{numrows} rows to : #{sheet_name}"
|
|
149
142
|
# Create required sheet
|
|
150
|
-
|
|
143
|
+
create(sheet)
|
|
151
144
|
|
|
152
|
-
row_index =
|
|
145
|
+
row_index = num_rows
|
|
153
146
|
# write header line
|
|
154
|
-
if
|
|
147
|
+
if header && row_index == 0
|
|
155
148
|
header_row = @sheet.createRow(row_index)
|
|
156
149
|
cell_index = 0
|
|
157
|
-
results[0].keys.each
|
|
158
|
-
header_row.createCell(cell_index).setCellValue(
|
|
159
|
-
@sheet.setDefaultColumnStyle(cell_index,
|
|
150
|
+
results[0].keys.each do |h|
|
|
151
|
+
header_row.createCell(cell_index).setCellValue(h.to_s)
|
|
152
|
+
@sheet.setDefaultColumnStyle(cell_index, getPercentStyle) if h.to_s.include? '%'
|
|
160
153
|
cell_index += 1
|
|
161
|
-
|
|
154
|
+
end
|
|
162
155
|
# Freeze the header row
|
|
163
156
|
@sheet.createFreezePane( 0, 1, 0, 1 )
|
|
164
157
|
row_index += 1
|
|
165
158
|
end
|
|
166
159
|
|
|
167
160
|
# write_results
|
|
168
|
-
results.each
|
|
161
|
+
results.each do |row|
|
|
169
162
|
sheet_row = @sheet.createRow(row_index)
|
|
170
163
|
cell_index = 0
|
|
171
|
-
row.each
|
|
172
|
-
celltype = v.
|
|
164
|
+
row.each do |_k, v|
|
|
165
|
+
celltype = v.is_a?(Numeric) ? HSSFCell::CELL_TYPE_NUMERIC : HSSFCell::CELL_TYPE_STRING
|
|
173
166
|
cell = sheet_row.createCell(cell_index, celltype)
|
|
174
167
|
|
|
175
|
-
v.nil? ?
|
|
168
|
+
value = v.nil? ? '<NIL>' : v
|
|
176
169
|
|
|
177
170
|
cell.setCellValue(value)
|
|
178
171
|
|
|
179
|
-
cell_index +=1
|
|
180
|
-
|
|
181
|
-
#puts "#{sheet}: written row #{row_index}"
|
|
182
|
-
row_index +=1
|
|
183
|
-
|
|
172
|
+
cell_index += 1
|
|
173
|
+
end
|
|
174
|
+
# puts "#{sheet}: written row #{row_index}"
|
|
175
|
+
row_index += 1
|
|
176
|
+
end
|
|
184
177
|
end
|
|
185
178
|
end
|
|
186
|
-
|
|
179
|
+
|
|
187
180
|
module ExcelHelper
|
|
188
181
|
require 'java'
|
|
189
182
|
|
|
@@ -197,16 +190,16 @@ if(DataShift::Guards::jruby?)
|
|
|
197
190
|
|
|
198
191
|
# ActiveRecord Helper - Export model data to XLS file format
|
|
199
192
|
#
|
|
200
|
-
def to_xls(items=[])
|
|
193
|
+
def to_xls(items = [])
|
|
201
194
|
|
|
202
195
|
@excel = ExcelFile.new(items[0].class.name)
|
|
203
|
-
|
|
196
|
+
|
|
204
197
|
@excel.create_row(0)
|
|
205
|
-
|
|
198
|
+
|
|
206
199
|
sheet = @excel.sheet
|
|
207
200
|
|
|
208
201
|
# header row
|
|
209
|
-
|
|
202
|
+
unless items.empty?
|
|
210
203
|
row = sheet.createRow(0)
|
|
211
204
|
cell_index = 0
|
|
212
205
|
items[0].class.columns.each do |column|
|
|
@@ -218,16 +211,16 @@ if(DataShift::Guards::jruby?)
|
|
|
218
211
|
# value rows
|
|
219
212
|
row_index = 1
|
|
220
213
|
items.each do |item|
|
|
221
|
-
row = sheet.createRow(row_index)
|
|
214
|
+
row = sheet.createRow(row_index)
|
|
222
215
|
|
|
223
216
|
cell_index = 0
|
|
224
217
|
item.class.columns.each do |column|
|
|
225
218
|
cell = row.createCell(cell_index)
|
|
226
|
-
if column.sql_type =~ /date/
|
|
219
|
+
if column.sql_type =~ /date/
|
|
227
220
|
millis = item.send(column.name).to_f * 1000
|
|
228
221
|
cell.setCellValue(Date.new(millis))
|
|
229
|
-
cell.setCellStyle(dateStyle)
|
|
230
|
-
elsif column.sql_type =~ /int/
|
|
222
|
+
cell.setCellStyle(dateStyle)
|
|
223
|
+
elsif column.sql_type =~ /int/
|
|
231
224
|
cell.setCellValue(item.send(column.name).to_i)
|
|
232
225
|
else
|
|
233
226
|
value = item.send(column.name)
|
|
@@ -241,4 +234,4 @@ if(DataShift::Guards::jruby?)
|
|
|
241
234
|
end
|
|
242
235
|
end
|
|
243
236
|
end
|
|
244
|
-
end
|
|
237
|
+
end
|