Class: HsdsTransformer::BaseTransformer
- Inherits:
-
Object
- Object
- HsdsTransformer::BaseTransformer
- Defined in:
- lib/hsds_transformer/base_transformer.rb
Direct Known Subclasses
Constant Summary collapse
- SUPPORTED_HSDS_MODELS =
%w(organizations services locations physical_addresses postal_addresses phones service_taxonomies regular_schedules taxonomies accessibility_for_disabilities contacts languages eligibilities services_at_locations service_areas)
Constants included from FilePaths
FilePaths::DEFAULT_INPUT_PATH, FilePaths::DEFAULT_OUTPUT_PATH
Constants included from Headers
Headers::ACCESSIBILITY_FOR_DISABILITIES_HEADERS, Headers::CONTACTS_HEADERS, Headers::ELIGIBILITIES_HEADERS, Headers::LANGUAGES_HEADERS, Headers::LOCATIONS_HEADERS, Headers::ORGANIZATIONS_HEADERS, Headers::PHONES_HEADERS, Headers::PHYSICAL_ADDRESSES_HEADERS, Headers::POSTAL_ADDRESSES_HEADERS, Headers::REGULAR_SCHEDULES_HEADERS, Headers::SERVICES_AT_LOCATIONS_HEADERS, Headers::SERVICES_HEADERS, Headers::SERVICE_AREAS_HEADERS, Headers::SERVICE_TAXONOMIES_HEADERS, Headers::TAXONOMIES_HEADERS
Instance Attribute Summary collapse
-
#include_custom ⇒ Object
readonly
Returns the value of attribute include_custom.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Attributes included from FilePaths
#default_datapackage_json_path, #input_path, #output_accessibility_for_disabilities_path, #output_contacts_path, #output_data_path, #output_datapackage_file_path, #output_datapackage_path, #output_eligibilities_path, #output_languages_path, #output_locations_path, #output_organizations_path, #output_path, #output_phones_path, #output_physical_addresses_path, #output_postal_addresses_path, #output_regular_schedules_path, #output_service_areas_path, #output_service_taxonomies_path, #output_services_at_locations_path, #output_services_path, #output_taxonomies_path, #zipfile_name
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_custom_transformation ⇒ Object
This is defined in custom transformer if there is one.
-
#initialize(args) ⇒ BaseTransformer
constructor
TODO validate that incoming data is valid-ish, like unique IDs.
- #transform ⇒ Object
- #transform_file(input_file_name, file_mapping) ⇒ Object
Methods included from FilePaths
Methods included from Headers
Constructor Details
#initialize(args) ⇒ BaseTransformer
TODO validate that incoming data is valid-ish, like unique IDs
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hsds_transformer/base_transformer.rb', line 15 def initialize(args) @mapping = parse_mapping(args[:mapping]) @include_custom = args[:include_custom] @zip_output = args[:zip_output] SUPPORTED_HSDS_MODELS.each do |model| var_name = "@" + model instance_variable_set(var_name, []) end set_file_paths(args) end |
Instance Attribute Details
#include_custom ⇒ Object (readonly)
Returns the value of attribute include_custom.
6 7 8 |
# File 'lib/hsds_transformer/base_transformer.rb', line 6 def include_custom @include_custom end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
6 7 8 |
# File 'lib/hsds_transformer/base_transformer.rb', line 6 def mapping @mapping end |
Class Method Details
.run(args) ⇒ Object
10 11 12 |
# File 'lib/hsds_transformer/base_transformer.rb', line 10 def self.run(args) new(args).transform end |
Instance Method Details
#apply_custom_transformation ⇒ Object
This is defined in custom transformer if there is one
66 67 |
# File 'lib/hsds_transformer/base_transformer.rb', line 66 def apply_custom_transformation end |
#transform ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hsds_transformer/base_transformer.rb', line 29 def transform # Initial transformation into HSDS mapping.each do |input_file_name, file_mapping| transform_file(input_file_name, file_mapping) end # HSDS additional formatting singletonize_languages apply_custom_transformation # make data path for these files Dir.mkdir(output_datapackage_path) unless Dir.exists?(output_datapackage_path) Dir.mkdir(output_data_path) unless Dir.exists?(output_data_path) # Write the data to CSV files write_output_files zip_output if @zip_output return self end |
#transform_file(input_file_name, file_mapping) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hsds_transformer/base_transformer.rb', line 52 def transform_file(input_file_name, file_mapping) path = @input_path + input_file_name org_mapping = file_mapping["columns"] # Now we want to process each row in a way that allows the row to create multiple objects, # including multiple objects from the same rows. CSV.foreach(path, headers: true) do |input| collected_data = hsds_objects_from_row(input, org_mapping) collect_into_ivars(collected_data) end end |