Class: Libis::Tools::SharepointMapping

Inherits:
Hash show all
Defined in:
lib/libis/tools/metadata/sharepoint_mapping.rb

Overview

Copy of old Sharepoint mapping class. Needs inspection and probably a mayor update.

Instance Method Summary collapse

Methods inherited from Hash

#cleanup, #key_strings_to_symbols, #key_strings_to_symbols!, #key_symbols_to_strings, #key_symbols_to_strings!, #recursive_cleanup, #recursive_merge, #recursive_merge!

Constructor Details

#initialize(mapping_file) ⇒ SharepointMapping

Returns a new instance of SharepointMapping.



14
15
16
17
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
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 14

def initialize(mapping_file)


  CSV.foreach(mapping_file, headers: true, skip_blanks: true) do |row|
    next unless row[1]
    # next unless (row[2] || row[3])

    # compensation for bug in library that reads the Excel data
    0.upto(5) { |i| row[i] = row[i].gsub(/_x005F(_x[0-9a-fA-F]{4}_)/, '\1') if row[i] }

    name = row[0] ? row[0].strip : nil
    label = row[1].strip.to_sym
    dc_tag = row[2] ? row[2].strip : ''
    db_column = row[3] ? row[3].strip : nil
    db_datatype = row[4] ? row[4].strip.upcase.to_sym : nil
    db_valuemask = row[5] ? row[5] : nil
    #      scope_tag = row[6] ? row[6].strip : nil
    #      scope_id = (row[7] and row[7] =~ /[0-9]+/ ? Integer(row[7].strip) : nil)


    mapping = {}
    mapping[:fancy_name] = name if name
    mapping[:db_column] = db_column if db_column
    mapping[:db_datatype] = :STRING
    mapping[:db_datatype] = db_datatype if db_datatype
    mapping[:db_valuemask] = (mapping[:db_datatype] == :STRING ? "'@@'" : '@@')
    mapping[:db_valuemask] = db_valuemask if db_valuemask
    #      mapping[:scope_tag] = scope_tag if scope_tag
    #      mapping[:scope_id] = scope_id if scope_id

    if dc_tag.match(/^\s*"(.*)"\s*(<.*)$/)
      mapping[:dc_prefix] = $1
      dc_tag = $2
    end

    if dc_tag.match(/^\s*<dc:[^.]+\.([^.>]+)>(.*)$/)
      mapping[:dc_tag] = "dcterms:#{$1}"
      dc_tag = $2

    elsif dc_tag.match(/^\s*<dc:([^.>]+)>(.*)$/)
      mapping[:dc_tag] = "dc:#{$1}"
      dc_tag = $2
    end

    if dc_tag.match(/^\s*"(.*)"\s*$/)
      mapping[:dc_postfix] = $1
    end

    self[label] = mapping.empty? ? nil : mapping

  end

  File.open('mapping.yml', 'wt') { |fp|
    fp.puts self.to_yaml
  }
  super nil

end

Instance Method Details

#db_column(label) ⇒ Object



103
104
105
106
107
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 103

def db_column(label)
  mapping = self[label]
  mapping = mapping[:db_column] if mapping
  mapping
end

#db_value(label, value) ⇒ Object



109
110
111
112
113
114
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 109

def db_value(label, value)
  mapping = self[label]
  return nil unless mapping
  mask = mapping[:db_valuemask]
  mask.gsub('@@', value.to_s)
end

#dc_postfix(label) ⇒ Object



97
98
99
100
101
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 97

def dc_postfix(label)
  mapping = self[label]
  mapping = mapping[:dc_postfix] if mapping
  mapping
end

#dc_prefix(label) ⇒ Object



91
92
93
94
95
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 91

def dc_prefix(label)
  mapping = self[label]
  mapping = mapping[:dc_prefix] if mapping
  mapping
end

#dc_tag(label) ⇒ Object



85
86
87
88
89
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 85

def dc_tag(label)
  mapping = self[label]
  mapping = mapping[:dc_tag] if mapping
  mapping
end

#fancy_label(label) ⇒ Object



79
80
81
82
83
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 79

def fancy_label(label)
  mapping = self[label]
  mapping = mapping[:fancy_name] if mapping
  "#{label}#{mapping ? '(' + mapping + ')' : ''}"
end

#name(label) ⇒ Object



73
74
75
76
77
# File 'lib/libis/tools/metadata/sharepoint_mapping.rb', line 73

def name(label)
  mapping = self[label]
  mapping = mapping[:fancy_name] if mapping
  mapping || label
end