lib/marcspec/kvmap.rb in marcspec-0.6.0 vs lib/marcspec/kvmap.rb in marcspec-0.7.0
- old
+ new
@@ -6,10 +6,12 @@
module MARCSpec
# A KVMap is, when push comes to shove, just a hash with a name, and the
# option of adding a default value for each lookup.
+ #
+ # The map portion of a kvmap is simply a hash.
class KVMap < Map
# Basic lookup which takes a lookup key and an optional default value,
# which will be returned iff the map doesn't have
@@ -36,26 +38,36 @@
return default
end
end
end
+ # Set an element in the map, just like for a regular hash
def []= key, value
@map[key] = value
end
alias_method :add, :[]=
+
+ # Produce a configuration file that will round-trip to this object.
+ #
+ # @return [String] A string representation of valid ruby code that can be turned back into
+ # this object using MARCSpec::Map#fromFile
def asPPString
s = StringIO.new
s.print "{\n :maptype=>:kv,\n :mapname=>"
PP.singleline_pp(@mapname, s)
s.print ",\n :map => "
PP.pp(@map, s)
s.puts "\n}"
return s.string
end
-
+
+ # Translate from a solrmarc map file that has *already been determined* to be a KV map
+ # @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|