marcspec 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.7.3
2
+ * Squashed a bug where I forgot to deal with escaping in java .properties files. Now I'm just using
3
+ a real Java Properties object so I don't have to worry about it.
1
4
  0.7.2
2
5
  * Also change methodArgs to functionArgs
3
6
  0.7.1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
@@ -64,6 +64,10 @@ module MARCSpec
64
64
 
65
65
 
66
66
  # Translate from a solrmarc map file that has *already been determined* to be a KV map
67
+ #
68
+ # Uses the underlying java Properties class to avoid having to rewrite all the esacping
69
+ # logic.
70
+ #
67
71
  # @param [String] filename The path to the solrmarc kv map file
68
72
  # @return [MARCSpec::KVMap] a KVMap
69
73
 
@@ -71,20 +75,15 @@ module MARCSpec
71
75
  mapname = File.basename(filename).sub(/\..+?$/, '')
72
76
  map = {}
73
77
  File.open(filename) do |smf|
74
- smf.each_line do |l|
75
- l.chomp!
76
- next unless l =~ /\S/
77
- l.strip!
78
- next if l =~ /^#/
79
- unless l =~ /^(.+?)\s*=\s*(.+)$/
80
- $LOG.warn "KVMap import skipping weird line in #{filename}\n #{l}"
81
- next
82
- end
83
- map[$1] = $2
78
+ prop = Java::java.util.Properties.new
79
+ prop.load(smf.to_inputstream)
80
+ prop.each do |k,v|
81
+ map[k] = v
84
82
  end
85
83
  end
86
84
  return self.new(mapname, map)
87
85
  end
86
+
88
87
 
89
88
 
90
89
  end
@@ -36,15 +36,17 @@ module MARCSpec
36
36
  mapname = File.basename(filename).sub(/\..+?$/, '')
37
37
  kvlist = []
38
38
  File.open(filename) do |f|
39
- f.each_line do |line|
40
- match = /^pattern.*?=\s*(.*?)\s*=>\s*(.*?)\s*$/.match(line)
41
- unless match
39
+ prop = Java::java.util.Properties.new
40
+ prop.load(f.to_inputstream)
41
+ prop.each do |patstring,kv|
42
+ unless patstring =~ /^pattern/ and kv =~ /.+=>.+/
42
43
  $LOG.warn "MultiValueMap import skipping weird line in #{filename}\n #{l}"
43
44
  next
44
45
  end
46
+ match = /^\s*(.+?)\s*=>\s*(.+?)\s*$/.match(kv)
45
47
  kvlist << [Regexp.new(match[1]), match[2]]
46
48
  end
47
- end
49
+ end
48
50
  return self.new(mapname, kvlist)
49
51
  end
50
52
 
data/lib/marcspec.rb CHANGED
@@ -17,15 +17,9 @@ require "marcspec/marcfieldspec"
17
17
  # It's just a hash.
18
18
 
19
19
  module CacheSpot
20
- def cacheadd k, v
20
+ def cachespot
21
21
  @_cachespot ||= {}
22
- @_cachespot[k] = v
23
- return v
24
- end
25
-
26
- def cacheget k
27
- @_cachespot ||= {}
28
- return @_cachespot[k]
22
+ return @_cachespot
29
23
  end
30
24
  end
31
25
 
data/spec/maps_spec.rb CHANGED
@@ -56,6 +56,13 @@ describe "Maps" do
56
56
  map["nl"].should.equal "New Caledonia"
57
57
  end
58
58
 
59
+ it "should correctly deal with solrmarc files with escaped chars (via \\)" do
60
+ map = MARCSpec::KVMap.from_solrmarc_file "#{DIR}/data/umich/translation_maps/location_map.properties"
61
+ map['AAEL'].should.equal 'AAEL'
62
+ map['AAEL MICE'].should.equal 'AAEL MICE'
63
+ map['BUHR AAEL'].should.equal 'BUHR'
64
+ end
65
+
59
66
  it "should read a pattern solrmarc file" do
60
67
  map = MARCSpec::MultiValueMap.from_solrmarc_file "#{DIR}/data/umich/translation_maps/library_map.properties"
61
68
  map.mapname.should.equal 'library_map'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcspec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 2
10
- version: 0.7.2
9
+ - 3
10
+ version: 0.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - BillDueber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-19 00:00:00 -04:00
18
+ date: 2010-08-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency