Class: Libis::Metadata::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/libis/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



18
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/metadata/mapper.rb', line 18

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|
        # noinspection RubyStringKeysInHashInspection
        @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.



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

def format_parser
  @format_parser
end

#mappingObject (readonly)

Returns the value of attribute mapping.



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

def mapping
  @mapping
end

#selection_parserObject (readonly)

Returns the value of attribute selection_parser.



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

def selection_parser
  @selection_parser
end

#tablesObject (readonly)

Returns the value of attribute tables.



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

def tables
  @tables
end

#target_parserObject (readonly)

Returns the value of attribute target_parser.



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

def target_parser
  @target_parser
end