lib/marcspec/kvmap.rb in marcspec-0.7.2 vs lib/marcspec/kvmap.rb in marcspec-0.7.3
- old
+ new
@@ -62,30 +62,29 @@
return s.string
end
# Translate from a solrmarc map file that has *already been determined* to be a KV map
+ #
+ # Uses the underlying java Properties class to avoid having to rewrite all the esacping
+ # logic.
+ #
# @param [String] filename The path to the solrmarc kv map file
# @return [MARCSpec::KVMap] a KVMap
def self.from_solrmarc_file filename
mapname = File.basename(filename).sub(/\..+?$/, '')
map = {}
File.open(filename) do |smf|
- smf.each_line do |l|
- l.chomp!
- next unless l =~ /\S/
- l.strip!
- next if l =~ /^#/
- unless l =~ /^(.+?)\s*=\s*(.+)$/
- $LOG.warn "KVMap import skipping weird line in #{filename}\n #{l}"
- next
- end
- map[$1] = $2
+ prop = Java::java.util.Properties.new
+ prop.load(smf.to_inputstream)
+ prop.each do |k,v|
+ map[k] = v
end
end
return self.new(mapname, map)
end
+
end
end