-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from psu-libraries/176-punctuation-fix
right to left language formatting
- Loading branch information
Showing
8 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,6 @@ config/environments/*.local.yml | |
.bash_history | ||
.cache | ||
.local | ||
.envrc | ||
data/ | ||
vendor/**/* |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module PsulibTraject::Processors | ||
class PubDisplay | ||
def initialize(field, context) | ||
@context = context | ||
@field = field | ||
end | ||
|
||
def call | ||
return if final.nil? | ||
|
||
final[1] = vern_clean unless vern.nil? | ||
end | ||
|
||
private | ||
|
||
attr_accessor :context, :field | ||
|
||
def vern | ||
final.length <= 1 ? nil : final[1] | ||
end | ||
|
||
def final | ||
context.output_hash["#{field}_display_ssm"] | ||
end | ||
|
||
def vern_clean | ||
return vern unless /[\u0621-\u064A]+\.$/.match?(vern) # regex to check for arabic | ||
|
||
vern_value = vern.gsub('.', '') | ||
".#{vern_value}" | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec::Matchers.define_negated_matcher :not_include, :include | ||
|
||
RSpec.describe 'Publication' do | ||
let(:leader) { '1234567890' } | ||
|
||
describe 'Record with a right to left vernacular edition' do | ||
let(:field) { 'edition_display_ssm' } | ||
let(:edition_250) do | ||
{ '250' => { 'subfields' => [{ '6' => '880-03' }, | ||
{ 'a' => 'Chāp-i avval.' }] } } | ||
end | ||
let(:edition_vern_250) do | ||
{ '880' => { 'subfields' => [{ '6' => '250-03' }, | ||
{ 'a' => 'چاپ اول.' }] } } | ||
end | ||
let(:result) { indexer.map_record(MARC::Record.new_from_hash('fields' => [edition_250, edition_vern_250], 'leader' => leader)) } | ||
|
||
it 'has the vernacular edition with a period on the left in the edition statement' do | ||
expect(result[field]).to eq ['Chāp-i avval.', '.چاپ اول'] | ||
expect(result[field].length).to eq 2 | ||
end | ||
|
||
it 'has empty vern and latin edition field' do | ||
expect(result).not_to include('edition_vern') | ||
expect(result).not_to include('edition_latin') | ||
end | ||
end | ||
|
||
describe 'Record with a left to right vernacular edition' do | ||
let(:field) { 'edition_display_ssm' } | ||
let(:edition_250) do | ||
{ '250' => { 'subfields' => [{ '6' => '880-03' }, | ||
{ 'a' => 'Tōkyō : Hayakawa Shobō, 1999.' }] } } | ||
end | ||
let(:edition_vern_250) do | ||
{ '880' => { 'subfields' => [{ '6' => '250-03' }, | ||
{ 'a' => '東京 : 早川書房, 1999.' }] } } | ||
end | ||
let(:result) { indexer.map_record(MARC::Record.new_from_hash('fields' => [edition_250, edition_vern_250], 'leader' => leader)) } | ||
|
||
it 'has the vernacular edition with a period on the right in the edition statement' do | ||
expect(result[field]).to eq ['Tōkyō : Hayakawa Shobō, 1999.', '東京 : 早川書房, 1999.'] | ||
expect(result[field].length).to eq 2 | ||
end | ||
|
||
it 'has empty vern and latin edition field' do | ||
expect(result).not_to include('edition_vern') | ||
expect(result).not_to include('edition_latin') | ||
end | ||
end | ||
|
||
describe 'Record with no vernacular edition' do | ||
let(:field) { 'edition_display_ssm' } | ||
let(:edition_250) do | ||
{ '250' => { 'subfields' => [{ '6' => '880-03' }, | ||
{ 'a' => 'First Edition.' }] } } | ||
end | ||
let(:result) { indexer.map_record(MARC::Record.new_from_hash('fields' => [edition_250], 'leader' => leader)) } | ||
|
||
it 'has the vernacular edition with a period on the right in the edition statement' do | ||
expect(result[field]).to eq ['First Edition.'] | ||
expect(result[field].length).to eq 1 | ||
end | ||
|
||
it 'has empty vern and latin edition field' do | ||
expect(result).not_to include('edition_vern') | ||
expect(result).not_to include('edition_latin') | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe PsulibTraject::Processors::PubDisplay do | ||
let(:context) { instance_double 'Context' } | ||
|
||
before do | ||
allow(context).to receive(:output_hash).and_return(output_hash) | ||
end | ||
|
||
describe '::call' do | ||
context 'when there is not a vernacular version of the field' do | ||
let(:output_hash) do | ||
{ 'edition_display_ssm' => ['thing'] } | ||
end | ||
|
||
it 'sets the field_display_ssm to the field_latin and deletes field_latin' do | ||
described_class.new('edition', context).call | ||
expect(output_hash['edition_display_ssm']).to eq ['thing'] | ||
end | ||
end | ||
|
||
context 'when there is a vernacular version of the field' do | ||
context 'when field_vern contains right to left arabic equals sign' do | ||
context 'when there is a period on the right end of field_vern' do | ||
let(:output_hash) do | ||
{ 'edition_display_ssm' => ['Chāp-i avval.', 'چاپ اول.'] } | ||
end | ||
|
||
it 'moves the period of the vern to the left, adds field_latin & field_vern to field_display_ssm, and deletes field_latin and field_vern' do | ||
described_class.new('edition', context).call | ||
expect(output_hash['edition_display_ssm']).to eq ['Chāp-i avval.', '.چاپ اول'] | ||
end | ||
end | ||
|
||
context 'when there is not a period on the right end of field_vern' do | ||
let(:output_hash) do | ||
{ 'edition_display_ssm' => ['Chāp-i avval.', 'چاپ اول'] } | ||
end | ||
|
||
it 'does not change the field_vern, adds field_latin & field_vern to field_display_ssm, and deletes field_latin and field_vern' do | ||
described_class.new('edition', context).call | ||
expect(output_hash['edition_display_ssm']).to eq ['Chāp-i avval.', 'چاپ اول'] | ||
end | ||
end | ||
end | ||
|
||
context 'when field_vern does not contain right to left arabic equals sign' do | ||
let(:output_hash) do | ||
{ 'edition_display_ssm' => ['Tōkyō : Hayakawa Shobō, 1999.', '東京 : 早川書房, 1999.'] } | ||
end | ||
|
||
it 'adds field_latin & field_vern to field_display_ssm and deletes field_latin and field_vern' do | ||
described_class.new('edition', context).call | ||
expect(output_hash['edition_display_ssm']).to eq ['Tōkyō : Hayakawa Shobō, 1999.', '東京 : 早川書房, 1999.'] | ||
end | ||
end | ||
end | ||
end | ||
end |