Class: DS::Mapper::BaseMapper
- Inherits:
-
Object
- Object
- DS::Mapper::BaseMapper
- Defined in:
- lib/ds/mapper/base_mapper.rb
Overview
DS::Mapper::BaseMapper abstract Mapper class. Implementing classes map DS sources records to CSV rows.
Implementing classes must implement:
-
#extract_record -
#map_record
Direct Known Subclasses
Constant Summary collapse
- PLACES_COLUMN_MAP =
{ production_place_as_recorded: :place_as_recorded, production_place_ds_qid: :ds_qid }
- TITLES_COLUMN_MAP =
{ title_as_recorded: :title_as_recorded, title_as_recorded_agr: :title_as_recorded_agr, uniform_title_as_recorded: :uniform_title_as_recorded, uniform_title_agr: :uniform_title_as_recorded_agr, standard_title_ds_qid: :ds_qid }
- GENRES_COLUMN_MAP =
{ genre_as_recorded: :genre_as_recorded, genre_ds_qid: :ds_qid }
- SUBJECTS_COLUMN_MAP =
{ subject_as_recorded: :subject_as_recorded, subject_ds_qid: :ds_qid, }
- AUTHORS_COLUMN_MAP =
{ author_as_recorded: :name_as_recorded, author_as_recorded_agr: :name_agr, author_ds_qid: :ds_qid }
- ARTISTS_COLUMN_MAP =
{ artist_as_recorded: :name_as_recorded, artist_as_recorded_agr: :name_agr, artist_ds_qid: :ds_qid }
- SCRIBES_COLUMN_MAP =
{ scribe_as_recorded: :name_as_recorded, scribe_as_recorded_agr: :name_agr, scribe_ds_qid: :ds_qid }
- ASSOCIATED_AGENT_COLUMN_MAP =
{ associated_agent_as_recorded: :name_as_recorded, associated_agent_as_recorded_agr: :name_agr, associated_agent_ds_qid: :ds_qid }
- LANGUAGE_COLUMN_MAP =
{ language_as_recorded: :language_as_recorded, language_ds_qid: :ds_qid }
- FORMER_OWNER_COLUMN_MAP =
{ former_owner_as_recorded: :name_as_recorded, former_owner_as_recorded_agr: :name_agr, former_owner_ds_qid: :ds_qid }
- MATERIAL_COLUMN_MAP =
{ material_as_recorded: :material_as_recorded, material_ds_qid: :ds_qid }
- RECON_TYPE_COLUMN_MAP =
Maps recon type to column map
{ Recon::Type::Places => PLACES_COLUMN_MAP, Recon::Type::Titles => TITLES_COLUMN_MAP, Recon::Type::Genres => GENRES_COLUMN_MAP, Recon::Type::AllSubjects => SUBJECTS_COLUMN_MAP, Recon::Type::Authors => AUTHORS_COLUMN_MAP, Recon::Type::Artists => ARTISTS_COLUMN_MAP, Recon::Type::Scribes => SCRIBES_COLUMN_MAP, Recon::Type::AssociatedAgents => ASSOCIATED_AGENT_COLUMN_MAP, Recon::Type::Languages => LANGUAGE_COLUMN_MAP, Recon::Type::FormerOwners => FORMER_OWNER_COLUMN_MAP, Recon::Type::Materials => MATERIAL_COLUMN_MAP, }.freeze
Instance Attribute Summary collapse
-
#recon_builder ⇒ Object
readonly
Returns the value of attribute recon_builder.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_dir ⇒ Object
readonly
Returns the value of attribute source_dir.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#build_term_maps(extractor, record) ⇒ Hash<Symbol, String>
Creates an import CSV hash for the given record for all recon term types, using the given extractor.
-
#build_term_string(recons, recon_key) ⇒ String
Builds a term string by concatenating the values of the given reconstructions corresponding to the specified recon key, separated by ‘|’.
-
#build_term_strings(recons, column_map) ⇒ Hash
Builds term strings based on the given recons and column mapping.
-
#extract_record(entry) ⇒ Object
Extracts a record from the source for the given manifest entry.
-
#initialize(source_dir:, timestamp:, source:) ⇒ void
constructor
Initializes a new instance of the class.
-
#map_record(entry) ⇒ Hash<Symbol, String>
Maps a source record for the given manifest entry.
-
#map_terms(terms, recon_type, column_map) ⇒ Hash<Symbol,String>
Maps the given terms using the given recon type and column mapping.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(source_dir:, timestamp:, source:) ⇒ void
Initializes a new instance of the class.
104 105 106 107 108 109 |
# File 'lib/ds/mapper/base_mapper.rb', line 104 def initialize source_dir:, timestamp:, source: @recon_builder = Recon::ReconBuilder.new source_type: source.source_type, files: [], out_dir: [] @source = source @source_dir = source_dir @timestamp = end |
Instance Attribute Details
#recon_builder ⇒ Object (readonly)
Returns the value of attribute recon_builder.
17 18 19 |
# File 'lib/ds/mapper/base_mapper.rb', line 17 def recon_builder @recon_builder end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
16 17 18 |
# File 'lib/ds/mapper/base_mapper.rb', line 16 def source @source end |
#source_dir ⇒ Object (readonly)
Returns the value of attribute source_dir.
15 16 17 |
# File 'lib/ds/mapper/base_mapper.rb', line 15 def source_dir @source_dir end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
14 15 16 |
# File 'lib/ds/mapper/base_mapper.rb', line 14 def @timestamp end |
Instance Method Details
#build_term_maps(extractor, record) ⇒ Hash<Symbol, String>
Creates an import CSV hash for the given record for all recon term types, using the given extractor. The extractor is one of
DS::Extractor::MarcXml
DS::Extractor::TeiXml
DS::Extractor::DsCsvExtractor
DS::Extractor::DsMetsXml
The following recon term types are mapped for all records/extractors:
Recon::Type::Places
Recon::Type::Titles
Recon::Type::Genres
Recon::Type::Subjects
Recon::Type::Authors
Recon::Type::Artists
Recon::Type::Scribes
Recon::Type::AssociatedAgents
Recon::Type::Languages
Recon::Type::FormerOwners
Recon::Type::Materials
Column mappings are defined in DS::Mapper::RECON_TYPE_COLUMN_MAP
184 185 186 187 188 189 |
# File 'lib/ds/mapper/base_mapper.rb', line 184 def build_term_maps extractor, record RECON_TYPE_COLUMN_MAP.inject({}) { |hash, (recon_type, column_map)| terms = recon_type.method_name.flat_map { |method| extractor.send(method, record) } hash.update map_terms terms, recon_type, column_map } end |
#build_term_string(recons, recon_key) ⇒ String
Builds a term string by concatenating the values of the given reconstructions corresponding to the specified recon key, separated by ‘|’.
204 205 206 |
# File 'lib/ds/mapper/base_mapper.rb', line 204 def build_term_string recons, recon_key recons.map { |recon| recon[recon_key.to_sym] }.join('|') end |
#build_term_strings(recons, column_map) ⇒ Hash
Builds term strings based on the given recons and column mapping.
148 149 150 151 152 153 |
# File 'lib/ds/mapper/base_mapper.rb', line 148 def build_term_strings recons, column_map column_map.inject({}) do |hash, (import_csv_col, recon_key)| hash[import_csv_col] = build_term_string recons, recon_key hash end end |
#extract_record(entry) ⇒ Object
Extracts a record from the source for the given manifest entry.
120 121 122 |
# File 'lib/ds/mapper/base_mapper.rb', line 120 def extract_record entry raise NotImplementedError end |
#map_record(entry) ⇒ Hash<Symbol, String>
Maps a source record for the given manifest entry.
129 130 131 |
# File 'lib/ds/mapper/base_mapper.rb', line 129 def map_record entry raise NotImplementedError end |
#map_terms(terms, recon_type, column_map) ⇒ Hash<Symbol,String>
Maps the given terms using the given recon type and column mapping.
214 215 216 217 218 |
# File 'lib/ds/mapper/base_mapper.rb', line 214 def map_terms terms, recon_type, column_map recons = recon_builder.build_all_recons terms, recon_type term_strings = build_term_strings recons, column_map term_strings end |
#to_s ⇒ Object
:nodoc:
111 112 113 |
# File 'lib/ds/mapper/base_mapper.rb', line 111 def to_s # :nodoc: "#{self.class.name}: source_dir: #{source_dir}, timestamp: #{}, source: #{source}" end |