Last active
August 29, 2015 14:26
-
-
Save billdueber/0e05d7db014989cacb05 to your computer and use it in GitHub Desktop.
Traject extract_marc default value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'traject' | |
include Traject::Macros::Marc21 | |
r = MARC::Record.new | |
r << MARC::ControlField.new('001', '12345') | |
r << MARC::DataField.new('245', ' ', ' ', ['a', 'My Title']) | |
context = Traject::Indexer::Context.new | |
acc1 = [] | |
em1 = extract_marc('245a:999b', :default=>'Default Value') | |
em1.call(r,acc1, context) #=> acc1 == ['My Title'] | |
acc2 = [] | |
em2 = extract_marc('999b', :default=>'Default Value') | |
em2.call(r,acc2,context) #=> acc2 == ['Default Value'] | |
acc3 = [] | |
em3 = extract_marc('999b', :default => nil) | |
em3.call(r,acc3,context) #=> acc3 == [], not [nil] | |
class NullObject | |
def nil? | |
true | |
end | |
end | |
acc4 = [] | |
nobj = NullObject.new | |
em4 = extract_marc('999b', :default => nobj) | |
em4.call(r,acc4,context) #=> acc4 == [nobj] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment