mods_display 0.9.1 → 0.10.0

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
  SHA256:
3
- metadata.gz: 04b5809a32a151c63f3c9423f8917046060c12ed6a88a64e30b018f89256f144
4
- data.tar.gz: a2104c15cdec18e265fd19349fece71736a2e92f2c0bceb8288d7977a4ffa2a0
3
+ metadata.gz: 586a8299be19e795bc90b434d9902084ca8fa10bb8cbe9690fc108471e1f5495
4
+ data.tar.gz: 00574a48dc3c3ba050529bf2d3fcd5e38df5de4c0e5ed4023ad07904dea29c99
5
5
  SHA512:
6
- metadata.gz: 7f4505c49261d1a76e3f1ba8da36fce97a396c5a680de93ac61293d45aefde35716463172e0e92c29e90cbef2a8ed11b65ef9fa2787028e6f8be36f31dadf582
7
- data.tar.gz: afbf6a24b41cdc0c097f66b7ff7173501cfd1de626c1ed850e54c6e85319edd4af4484b46612e7828622b78469536ce8d859a8e1068bacb2461ac4d2c8385b25
6
+ metadata.gz: 9430fa89a1efb94a17ec8c83f5fc96e55f96221f962480ff6a71a9283548d385e1afabe1c8653215155a8d7804648075aae93d217ff2d25ec29357c5b2e64544
7
+ data.tar.gz: 0d7b2e673cae7f336e65824c528b78abd59e8b730430570faa98910cf715e875a707dde7787a48cbf158f15bc596b057181c443d253387136604b307036812ea
@@ -24,7 +24,7 @@ module ModsDisplay
24
24
  private
25
25
 
26
26
  def location_field_keys
27
- [:physicalLocation, :url, :shelfLocation, :holdingSimple, :holdingExternal]
27
+ [:physicalLocation, :url, :shelfLocator, :holdingSimple, :holdingExternal]
28
28
  end
29
29
 
30
30
  def location_label(element)
@@ -4,31 +4,10 @@ module ModsDisplay
4
4
  return_values = []
5
5
  if @values
6
6
  @values.each do |value|
7
- if displayForm(value)
8
- return_values << ModsDisplay::Values.new(
9
- label: displayLabel(value) || title_label(value),
10
- values: [displayForm(value)]
11
- )
12
- else
13
- nonSort = nil
14
- title = nil
15
- subTitle = nil
16
- nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
17
- title = value.title.text.strip unless value.title.text.strip.empty?
18
- subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
19
- preSubTitle = [nonSort, title].compact.join(' ')
20
- preSubTitle = nil if preSubTitle.strip.empty?
21
- preParts = compact_and_join_with_delimiter([preSubTitle, subTitle], ' : ')
22
- preParts = nil if preParts.strip.empty?
23
- parts = value.children.select do |child|
24
- %w(partName partNumber).include?(child.name)
25
- end.map(&:text).compact.join(parts_delimiter(value))
26
- parts = nil if parts.strip.empty?
27
- return_values << ModsDisplay::Values.new(
28
- label: displayLabel(value) || title_label(value),
29
- values: [compact_and_join_with_delimiter([preParts, parts], '. ')]
30
- )
31
- end
7
+ return_values << ModsDisplay::Values.new(
8
+ label: displayLabel(value) || title_label(value),
9
+ values: [assemble_title(value)]
10
+ )
32
11
  end
33
12
  end
34
13
  collapse_fields(return_values)
@@ -36,14 +15,42 @@ module ModsDisplay
36
15
 
37
16
  private
38
17
 
39
- def parts_delimiter(element)
40
- children = element.children.to_a
41
- # index will retun nil which is not comparable so we call 100
42
- # if the element isn't present (thus meaning it's at the end of the list)
43
- if (children.index { |c| c.name == 'partNumber' } || 100) < (children.index { |c| c.name == 'partName' } || 100)
44
- return ', '
18
+ def assemble_title(element)
19
+ return displayForm(element) if displayForm(element)
20
+
21
+ title = ''
22
+ previous_element = nil
23
+
24
+ element.children.select { |value| title_parts.include? value.name }.each do |value|
25
+ str = value.text.strip
26
+ next if str.empty?
27
+
28
+ delimiter = case
29
+ when title.empty?, title.end_with?(' ')
30
+ nil
31
+ when title.end_with?('.', ',', ':', ';')
32
+ ' '
33
+ when value.name == 'subTitle'
34
+ ' : '
35
+ when value.name == 'partName' && previous_element.name == 'partNumber'
36
+ ', '
37
+ when value.name == 'partNumber', value.name == 'partName'
38
+ '. '
39
+ else
40
+ ' '
41
+ end
42
+
43
+ title += delimiter if delimiter
44
+ title += str
45
+
46
+ previous_element = value
45
47
  end
46
- '. '
48
+
49
+ title
50
+ end
51
+
52
+ def title_parts
53
+ %w[nonSort title subTitle partName partNumber]
47
54
  end
48
55
 
49
56
  def title_label(element)
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = '0.9.1'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -5,7 +5,7 @@ describe ModsDisplay::Location do
5
5
  <<-XML
6
6
  <mods>
7
7
  <location>
8
- <shelfLocation>On Shelf A</shelfLocation>
8
+ <shelfLocator>On Shelf A</shelfLocator>
9
9
  </location>
10
10
  </mods>
11
11
  XML
@@ -15,6 +15,7 @@ describe ModsDisplay::Title do
15
15
  @multi_label = Stanford::Mods::Record.new.from_str(multi_label_fixture, false).title_info
16
16
  @alt_title = Stanford::Mods::Record.new.from_str(alt_title_fixture, false).title_info
17
17
  @title_punctuation = Stanford::Mods::Record.new.from_str(title_puncutation_fixture, false).title_info
18
+ @ordered_title_fixture = Stanford::Mods::Record.new.from_str(ordered_title_fixture, false).title_info
18
19
  end
19
20
  describe 'labels' do
20
21
  it 'should return a default label of Title if nothing else is available' do
@@ -70,5 +71,12 @@ describe ModsDisplay::Title do
70
71
  expect(values.first).not_to include '..'
71
72
  expect(values.first).to eq 'A title that ends in punctuation. 2015'
72
73
  end
74
+
75
+ it 'combines the title parts in the order from the record' do
76
+ values = mods_display_title(@ordered_title_fixture).fields.first.values
77
+ expect(values.length).to eq 1
78
+
79
+ expect(values.first).to eq 'The medium term expenditure framework (MTEF) for ... and the annual estimates for ... 016, Ministry of Tourism : expenditure to be met out of moneys granted and drawn from the consolidated fund, central government budget'
80
+ end
73
81
  end
74
82
  end
@@ -98,4 +98,18 @@ module TitleFixtures
98
98
  </mods>
99
99
  XML
100
100
  end
101
+
102
+ def ordered_title_fixture
103
+ <<-XML
104
+ <mods>
105
+ <titleInfo>
106
+ <nonSort>The</nonSort>
107
+ <title>medium term expenditure framework (MTEF) for ... and the annual estimates for ...</title>
108
+ <partNumber>016</partNumber>
109
+ <partName>Ministry of Tourism</partName>
110
+ <subTitle>expenditure to be met out of moneys granted and drawn from the consolidated fund, central government budget</subTitle>
111
+ </titleInfo>
112
+ </mods>
113
+ XML
114
+ end
101
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Keck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods