diff --git a/lib/alto_payload_delimited_transformer.rb b/lib/alto_payload_delimited_transformer.rb index 0518d67..67a3a65 100644 --- a/lib/alto_payload_delimited_transformer.rb +++ b/lib/alto_payload_delimited_transformer.rb @@ -12,7 +12,7 @@ def initialize(content) def namespaces @namespaces ||= begin - alto_ns = document.namespaces.values.first { |ns| ns.include? 'standards/alto/ns' } + alto_ns = document.namespaces.values.find { |ns| ns.include? 'standards/alto/ns' } { alto: alto_ns || 'http://www.loc.gov/standards/alto/ns-v3#' } end end diff --git a/spec/fixtures/bb018zb8894_04_0009_namespace_order.xml b/spec/fixtures/bb018zb8894_04_0009_namespace_order.xml new file mode 100644 index 0000000..1f804b9 --- /dev/null +++ b/spec/fixtures/bb018zb8894_04_0009_namespace_order.xml @@ -0,0 +1,45 @@ + + + +pixel +2016-08-04ABBYYABBYY Recognition Server4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/lib/alto_payload_delimited_transformer_spec.rb b/spec/lib/alto_payload_delimited_transformer_spec.rb index 0c2b3b7..4df625a 100644 --- a/spec/lib/alto_payload_delimited_transformer_spec.rb +++ b/spec/lib/alto_payload_delimited_transformer_spec.rb @@ -14,6 +14,16 @@ end end + context 'with an ALTO v2 document with ns-v3 namespace not first' do + subject(:transformer) { described_class.new(File.read('spec/fixtures/bb018zb8894_04_0009_namespace_order.xml')) } + + describe '#output' do + it 'returns a payload-delimited string' do + expect(transformer.output.first).to start_with 'George☞129,639,243,79 Stirling’s☞426,633,300,84 Heritage☞789,632,291,84' + end + end + end + context 'with an ALTO v3 document' do subject(:transformer) { described_class.new(File.read('spec/fixtures/EastTimor_Report_of_the_UNSG_2006_0001.xml')) }