stanford-mods 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -60,6 +60,7 @@ Example Using SearchWorks Mixins:
60
60
 
61
61
  == Releases
62
62
 
63
+ * <b>0.0.6</b> various title methods added to searchworks mixin
63
64
  * <b>0.0.5</b> main_author_w_date, additional_authors_w_dates added to Stanford::Mods::Record; various author methods added to searchworks mixin
64
65
  * <b>0.0.4</b> KolbRecord started
65
66
  * <b>0.0.3</b> began SearchWorks mixins with sw_access_facet and sw_language_facet
@@ -92,10 +92,34 @@ module Stanford
92
92
  def sw_sort_author
93
93
  # substitute java Character.MAX_CODE_POINT for nil main_author so missing main authors sort last
94
94
  val = '' + (main_author_w_date ? main_author_w_date : "\u{FFFF} ") + ( sort_title ? sort_title : '')
95
- val.gsub(/[[:punct:]]*/, '')
95
+ val.gsub(/[[:punct:]]*/, '').strip
96
96
  end
97
97
 
98
+ # ---- TITLE ----
99
+
100
+ # @return [String] value for title_245a_search field
101
+ def sw_short_title
102
+ short_titles ? short_titles.first : nil
103
+ end
104
+
105
+ # @return [String] value for title_245_search, title_display, title_full_display
106
+ def sw_full_title
107
+ full_titles ? full_titles.find { |s| s =~ Regexp.new(sw_short_title) } : nil
108
+ end
98
109
 
110
+ # this includes all titles except
111
+ # @return [Array<String>] values for title_variant_search
112
+ def sw_addl_titles
113
+ full_titles.select { |s| s !~ Regexp.new(sw_short_title) }
114
+ end
115
+
116
+ # Returns a sortable version of the main title
117
+ # @return [String] value for title_sort field
118
+ def sw_sort_title
119
+ val = '' + ( sort_title ? sort_title : '')
120
+ val.gsub(/[[:punct:]]*/, '').strip
121
+ end
122
+
99
123
  end # class Record
100
124
  end # Module Mods
101
125
  end # Module Stanford
@@ -1,5 +1,5 @@
1
1
  module Stanford
2
2
  module Mods
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -33,12 +33,12 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
33
33
  end
34
34
  end
35
35
 
36
- context "authors" do
36
+ context "sw author methods" do
37
37
  before(:all) do
38
38
  m = "<mods #{@ns_decl}><name type='personal'>
39
39
  <namePart type='given'>John</namePart>
40
40
  <namePart type='family'>Huston</namePart>
41
- <displayForm>q</displayForm>
41
+ <displayForm> q</displayForm>
42
42
  </name>
43
43
  <name type='personal'>
44
44
  <namePart>Crusty The Clown</namePart>
@@ -72,20 +72,20 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
72
72
  @smods_rec.should_receive(:additional_authors_w_dates) # in stanford-mods.rb
73
73
  @smods_rec.sw_addl_authors
74
74
  end
75
- it "person_authors (for author_person_facet, author_person_display)" do
75
+ it "person authors (for author_person_facet, author_person_display)" do
76
76
  @smods_rec.should_receive(:personal_names_w_dates) # in Mods gem
77
77
  @smods_rec.sw_person_authors
78
78
  end
79
79
  it "non-person authors (for author_other_facet)" do
80
80
  @smods_rec.sw_impersonal_authors.should == ['Watchful Eye, 1850-', 'Exciting Prints', 'plain', 'conference', 'family']
81
81
  end
82
- it "corporate_authors (for author_corp_display)" do
82
+ it "corporate authors (for author_corp_display)" do
83
83
  @smods_rec.sw_corporate_authors.should == ['Watchful Eye, 1850-', 'Exciting Prints']
84
84
  end
85
- it "meeting_authors (for author_meeting_display)" do
85
+ it "meeting authors (for author_meeting_display)" do
86
86
  @smods_rec.sw_meeting_authors.should == ['conference']
87
87
  end
88
- context "author sort" do
88
+ context "sort author" do
89
89
  it "should be a String" do
90
90
  @smods_rec.sw_sort_author.should == 'qJerk'
91
91
  end
@@ -107,12 +107,78 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
107
107
  r.sw_sort_author.should match("\u{FFFF}")
108
108
  r.sw_sort_author.should match("\xEF\xBF\xBF")
109
109
  end
110
- it "should not have any ascii punctuation marks" do
110
+ it "should not have any punctuation marks" do
111
111
  r = Stanford::Mods::Record.new
112
112
  r.from_str "<mods #{@ns_decl}><titleInfo><title>J,e.r;;;k</title></titleInfo></mods>"
113
113
  r.sw_sort_author.should =~ / Jerk$/
114
114
  end
115
115
  end
116
- end
116
+ end # context sw author methods
117
117
 
118
+ context "sw title methods" do
119
+ before(:all) do
120
+ m = "<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>"
121
+ @smods_rec.from_str m
122
+ end
123
+ context "short title (for title_245a_search, title_245a_display) " do
124
+ it "should call :short_titles" do
125
+ @smods_rec.should_receive(:short_titles) # in Mods gem
126
+ @smods_rec.sw_short_title
127
+ end
128
+ it "should be a String" do
129
+ @smods_rec.sw_short_title.should == 'The Jerk'
130
+ end
131
+ end
132
+ context "full title (for title_245_search, title_display, title_full_display)" do
133
+ it "should call :full_titles" do
134
+ @smods_rec.should_receive(:full_titles) # in Mods gem
135
+ @smods_rec.sw_full_title
136
+ end
137
+ it "should be a String" do
138
+ @smods_rec.sw_full_title.should == 'The Jerk A Tale of Tourettes'
139
+ end
140
+ end
141
+ context "additional titles (for title_variant_search)" do
142
+ before(:all) do
143
+ m = "<mods #{@ns_decl}>
144
+ <titleInfo type='alternative'><title>Alternative</title></titleInfo>
145
+ <titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>
146
+ <titleInfo><title>Joke</title></titleInfo>
147
+ </mods>"
148
+ @smods_rec.from_str(m)
149
+ @addl_titles = @smods_rec.sw_addl_titles
150
+ end
151
+ it "should not include the main title" do
152
+ @addl_titles.size.should == 2
153
+ @addl_titles.should_not include(@smods_rec.sw_full_title)
154
+ end
155
+ it "should include any extra main titles" do
156
+ @addl_titles.should include('Joke')
157
+ end
158
+ it "should include all alternative titles" do
159
+ @addl_titles.should include('Alternative')
160
+ end
161
+ end
162
+ context "sort title" do
163
+ it "should be a String" do
164
+ @smods_rec.sw_sort_title.should be_an_instance_of(String)
165
+ end
166
+ it "should use the sort title, as retrieved by :sort_title" do
167
+ @smods_rec.should_receive(:sort_title) # in Mods gem
168
+ @smods_rec.sw_sort_title
169
+ end
170
+ it "should not begin or end with whitespace" do
171
+ m = "<mods #{@ns_decl}>
172
+ <titleInfo><title> Jerk </title></titleInfo>
173
+ </mods>"
174
+ @smods_rec.from_str(m)
175
+ @smods_rec.sw_sort_title.should == @smods_rec.sw_sort_title.strip
176
+ end
177
+ it "should not have any punctuation marks" do
178
+ r = Stanford::Mods::Record.new
179
+ r.from_str "<mods #{@ns_decl}><titleInfo><title>J,e.r;;;k</title></titleInfo></mods>"
180
+ r.sw_sort_title.should =~ /^Jerk$/
181
+ end
182
+ end
183
+ end
118
184
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stanford-mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -170,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  segments:
172
172
  - 0
173
- hash: 2263895694555249166
173
+ hash: 1154889881956546953
174
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  none: false
176
176
  requirements:
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  segments:
181
181
  - 0
182
- hash: 2263895694555249166
182
+ hash: 1154889881956546953
183
183
  requirements: []
184
184
  rubyforge_project:
185
185
  rubygems_version: 1.8.24