traject 1.0.0.beta.5 → 1.0.0.beta.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a51fd70b21e067b49728f2c0fd90006d22586c2
4
- data.tar.gz: 8a451bfcb4d9509ae2795f671f6474d4f5fc645a
3
+ metadata.gz: ccc1ca6c023f01b9e21148a3ca37d86858df8065
4
+ data.tar.gz: 4360b687f3ba8d957d4a14d39bc6cefbd443bcdd
5
5
  SHA512:
6
- metadata.gz: b676d97ef3392006e199632fc8df2a5313e913af6b6071dda6217bf259ac61969fb392fb9b04a979f99713da0d14436abbee44b33fd5326b3bc54d3920481271
7
- data.tar.gz: f1de9d2a249a81777d1e7882eb5b3a47ac66d8dacdd8474bd65fafe3f59dcff8dc80f37e22ecb15bc7ede894e82cbe20b9abfec7c01926d88d79bb253970ca31
6
+ metadata.gz: dba976f724960b4048c2db65827780a46a2c64c442b2f48aa077375775f9f3a8901f446f226fd26f8e69cddbb696b3c114403c592b20cdc362bc43161a25f608
7
+ data.tar.gz: 7216d83c97aa75698d2c03dec2bcc263decf4cc3d39a62187e9b0b09856fa1cac45e4fcb524d633f8a77acbf474343a69fec9b0324b66f056eb888915396e95b
@@ -47,10 +47,6 @@ module Traject::Macros
47
47
  raise RuntimeError.new("Illegal/Unknown argument '#{(options.keys - EXTRACT_MARC_VALID_OPTIONS).join(', ')}' in extract_marc at #{Traject::Util.extract_caller_location(caller.first)}")
48
48
  end
49
49
 
50
- only_first = options.delete(:first)
51
- trim_punctuation = options.delete(:trim_punctuation)
52
- default_value = options.delete(:default)
53
- allow_duplicates = options.delete(:allow_duplicates)
54
50
 
55
51
  # We create the TranslationMap and the MarcExtractor here
56
52
  # on load, so the lambda can just refer to already created
@@ -61,6 +57,8 @@ module Traject::Macros
61
57
 
62
58
  if translation_map_arg = options.delete(:translation_map)
63
59
  translation_map = Traject::TranslationMap.new(translation_map_arg)
60
+ else
61
+ translation_map = nil
64
62
  end
65
63
 
66
64
 
@@ -68,29 +66,39 @@ module Traject::Macros
68
66
 
69
67
  lambda do |record, accumulator, context|
70
68
  accumulator.concat extractor.extract(record)
69
+ Marc21.apply_extraction_options(accumulator, options, translation_map)
70
+ end
71
+ end
72
+
73
+ # Side-effect the accumulator with the options
74
+ def self.apply_extraction_options(accumulator, options, translation_map=nil)
75
+ only_first = options[:first]
76
+ trim_punctuation = options[:trim_punctuation]
77
+ default_value = options[:default]
78
+ allow_duplicates = options[:allow_duplicates]
79
+
80
+ if only_first
81
+ accumulator.replace Array(accumulator[0])
82
+ end
71
83
 
72
- if only_first
73
- Marc21.first! accumulator
74
- end
75
-
76
- if translation_map
77
- translation_map.translate_array! accumulator
78
- end
79
-
80
- if trim_punctuation
81
- accumulator.collect! {|s| Marc21.trim_punctuation(s)}
82
- end
84
+ if translation_map
85
+ translation_map.translate_array! accumulator
86
+ end
83
87
 
84
- unless allow_duplicates
85
- accumulator.uniq!
86
- end
88
+ if trim_punctuation
89
+ accumulator.collect! {|s| Marc21.trim_punctuation(s)}
90
+ end
87
91
 
88
- if default_value && accumulator.empty?
89
- accumulator << default_value
90
- end
92
+ unless allow_duplicates
93
+ accumulator.uniq!
94
+ end
91
95
 
96
+ if default_value && accumulator.empty?
97
+ accumulator << default_value
92
98
  end
93
99
  end
100
+
101
+
94
102
  # A list of symbols that are valid keys in the options hash
95
103
  EXTRACT_MARC_VALID_OPTIONS = [:first, :trim_punctuation, :default,
96
104
  :allow_duplicates, :separator, :translation_map,
@@ -514,7 +514,7 @@ module Traject::Macros
514
514
  # customization you probably just want to write your own method in
515
515
  # terms of the Marc21Semantics.assemble_lcsh method.
516
516
  def marc_lcsh_formatted(options = {})
517
- spec = options[:spec] || "600:610:611:630:648:650:651:654:6662"
517
+ spec = options[:spec] || "600:610:611:630:648:650:651:654:662"
518
518
  subd_separator = options[:subdivison_separator] || " — "
519
519
  other_separator = options[:other_separator] || " "
520
520
 
@@ -1,3 +1,3 @@
1
1
  module Traject
2
- VERSION = "1.0.0.beta.5"
2
+ VERSION = "1.0.0.beta.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traject
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.5
4
+ version: 1.0.0.beta.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-30 00:00:00.000000000 Z
12
+ date: 2013-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: marc