Class: Libis::Tools::Metadata::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/libis/tools/metadata/mapper.rb

Overview

New style parsers and converters for metadata. New, not finished and untested.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selection_parser, target_parser, format_parser, config_xlsx) ⇒ Mapper

Returns a new instance of Mapper.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/libis/tools/metadata/mapper.rb', line 19

def initialize(selection_parser, target_parser, format_parser, config_xlsx)
  @selection_parser = selection_parser
  @target_parser = target_parser
  @format_parser = format_parser
  @mapping = []
  @tables = {}
  doc = SimpleXlsxReader.open(config_xlsx)
  doc.sheets.each do |sheet|
    if sheet.name == 'Mapping'
      mapping = sheet_to_hash(sheet)
      mapping.each do |rule|
        @mapping << {
            'Selection' => begin
              selection_parser.parse(rule['Selection'])
            rescue Parslet::ParseFailed => error
              puts "Error parsing '#{rule['Selection']}'"
              puts error.cause.ascii_tree
            end,
            'Target' => begin
              target_parser.parse(rule['Target'])
            rescue Parslet::ParseFailed => error
              puts "Error parsing '#{rule['Target']}'"
              puts error.cause.ascii_tree
            end,
            'Format' => begin
              format_parser.parse(rule['Format'])
            rescue Parslet::ParseFailed => error
              puts "Error parsing '#{rule['Format']}'"
              puts error.cause.ascii_tree
            end,
        }
      end
    else
      @tables[sheet.name] = sheet_to_hash(sheet)
    end
  end
  if @mapping.empty?
    raise RuntimeError, "Failure: config file '#{config_xlsx}' does not contain a 'Mapping' sheet."
  end
end

Instance Attribute Details

#format_parserObject (readonly)

Returns the value of attribute format_parser.



16
17
18
# File 'lib/libis/tools/metadata/mapper.rb', line 16

def format_parser
  @format_parser
end

#mappingObject (readonly)

Returns the value of attribute mapping.



17
18
19
# File 'lib/libis/tools/metadata/mapper.rb', line 17

def mapping
  @mapping
end

#selection_parserObject (readonly)

Returns the value of attribute selection_parser.



16
17
18
# File 'lib/libis/tools/metadata/mapper.rb', line 16

def selection_parser
  @selection_parser
end

#tablesObject (readonly)

Returns the value of attribute tables.



17
18
19
# File 'lib/libis/tools/metadata/mapper.rb', line 17

def tables
  @tables
end

#target_parserObject (readonly)

Returns the value of attribute target_parser.



16
17
18
# File 'lib/libis/tools/metadata/mapper.rb', line 16

def target_parser
  @target_parser
end