marcxella 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +201 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/marcxella.rb +8 -0
- data/lib/marcxella/collection.rb +15 -0
- data/lib/marcxella/controlfield.rb +32 -0
- data/lib/marcxella/datafield.rb +31 -0
- data/lib/marcxella/document.rb +34 -0
- data/lib/marcxella/record.rb +215 -0
- data/lib/marcxella/subfield.rb +13 -0
- data/lib/marcxella/version.rb +3 -0
- data/marcxella.gemspec +28 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 818c53efe060b3fedbc861cf45aa7c2c04d5125889c0a4c6cab89dbabe855bd2
|
4
|
+
data.tar.gz: 7ae14f0b769e7079c7ef8a1ce38c71e58a22e97468d7223a0c370eebe0a2fcfb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30563be727526b34ffc1b5b2f63d66c84cb19ec22089d3baa7361f5ffe999fb06886e75af6002e482bf9c49eef0e1afdb8ab662ee656e5936a4e81da24c69e2a
|
7
|
+
data.tar.gz: b9556a8950b2f9a2647a3496303916fc0e45470eda74bcd8d37ba62397c2529a188bad95a7152d98a18e3a91ceb563323119a50a88ddc2407d9b4ff773f45ece
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at github-smr@sneakemail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in marcxella.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Added at 2018-03-27 10:23:20 -0400 by seanredmond:
|
9
|
+
gem "nokogiri", "~> 1.8"
|
10
|
+
|
11
|
+
# Added at 2018-03-27 23:01:35 -0400 by sean:
|
12
|
+
gem "yard", "~> 0.9.12", :group => [:development]
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sean Redmond
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
# Marcxella
|
2
|
+
|
3
|
+
A simple interface to MARC-XML, for when you just need to parse some
|
4
|
+
MARC-XML quickly.
|
5
|
+
|
6
|
+
Pronounce it "marc-sélla".
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'marcxella'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install marcxella
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Documents
|
27
|
+
|
28
|
+
records (`Marcxella::Record`) are the main objects you'll be dealing with. To get at the records, you'll probably create a document. This can be done from a filehandle:
|
29
|
+
|
30
|
+
> require "marcxella"
|
31
|
+
> file = File.open("spec/xml/1027474578.xml")
|
32
|
+
> marc = Marcxella::Document.new(file)
|
33
|
+
|
34
|
+
You can also create a document from a string of XML:
|
35
|
+
|
36
|
+
> xml = File.open("spec/xml/1027474578.xml").read
|
37
|
+
> marc = Marcxella::Document.new(xml)
|
38
|
+
|
39
|
+
Marxcella uses Nokogiri internally, so you can also just pass a Nokogiri
|
40
|
+
document:
|
41
|
+
|
42
|
+
> doc = Nokogiri::XML(file)
|
43
|
+
> marc = Marcxella::Document.new(doc)
|
44
|
+
|
45
|
+
Once you have the document, you can get an array of the records:
|
46
|
+
|
47
|
+
> records = marc.records
|
48
|
+
|
49
|
+
If you want, you can create the records directly from Nokogiri nodes
|
50
|
+
|
51
|
+
> file = File.open("spec/xml/1027474578.xml")
|
52
|
+
> doc = Nokogiri::XML(file)
|
53
|
+
> records = doc.css('record').map{|r| Marcxella::Record.new(r)}
|
54
|
+
|
55
|
+
If the xml document contains collections, you can get the collections and then
|
56
|
+
get the records from those.
|
57
|
+
|
58
|
+
> first_coll = marc.collections.first
|
59
|
+
> records = first_coll.records
|
60
|
+
|
61
|
+
If the document does contain collections, `Marcxella::Document#records` will
|
62
|
+
simply ignore the collections and return an array of _all_ the records from
|
63
|
+
_all_ the collections.
|
64
|
+
|
65
|
+
### Records and fields
|
66
|
+
|
67
|
+
Once you have a record, you can get the fields by tag:
|
68
|
+
|
69
|
+
> rec = marc.records.first
|
70
|
+
> f = rec.field("001")
|
71
|
+
|
72
|
+
The `#field` method always returns an array, so even when you expect a single
|
73
|
+
field, you have to get it from the array. There is no distinction made between
|
74
|
+
repeating and non-repeating fields.
|
75
|
+
|
76
|
+
> control_number = rec.field("001").first
|
77
|
+
> title = rec.field("245").first
|
78
|
+
> subjects = rec.field("650")
|
79
|
+
|
80
|
+
Control fields and Data fields have different classes:
|
81
|
+
|
82
|
+
> control_number.class
|
83
|
+
=> Marcxella::ControlField
|
84
|
+
> title.class
|
85
|
+
=> Marcxella::DataField
|
86
|
+
|
87
|
+
All fields have tags and values:
|
88
|
+
|
89
|
+
> control_number.tag
|
90
|
+
=> "001"
|
91
|
+
> control_number.value
|
92
|
+
=> "1027474578"
|
93
|
+
|
94
|
+
> title.tag
|
95
|
+
=> "245"
|
96
|
+
> title.value
|
97
|
+
=> "Kindred /Octavia E. Butler."
|
98
|
+
|
99
|
+
`#to_s` returns the customary representation of the field data:
|
100
|
+
|
101
|
+
> control_number.to_s
|
102
|
+
=> "001 1027474578"
|
103
|
+
|
104
|
+
> title.to_s
|
105
|
+
=> "245 10$aKindred /$cOctavia E. Butler."
|
106
|
+
> puts title
|
107
|
+
245 10$aKindred /$cOctavia E. Butler.
|
108
|
+
|
109
|
+
Data fields have subfields. You can get an array of all of them or select an
|
110
|
+
array of subfields by code.
|
111
|
+
|
112
|
+
> title.subfields.count
|
113
|
+
=> 2
|
114
|
+
> title.subfield("a").first.to_s
|
115
|
+
=> "$aKindred /"
|
116
|
+
|
117
|
+
For compatibility, control fields have these methods, too, which always return
|
118
|
+
empty arrays:
|
119
|
+
|
120
|
+
> control_number.subfields
|
121
|
+
=> []
|
122
|
+
> control_number.subfield("a")
|
123
|
+
=> []
|
124
|
+
|
125
|
+
Subfields have codes, values, and string representations:
|
126
|
+
|
127
|
+
> subfield = rec.titleStatement.subfield("a").first
|
128
|
+
> subfield.code
|
129
|
+
=> "a"
|
130
|
+
> subfield.value
|
131
|
+
=> "Kindred /"
|
132
|
+
> subfield.to_s
|
133
|
+
=> "$aKindred /"
|
134
|
+
|
135
|
+
You can get all instances of a subfield of a given tag. For instance, to get all
|
136
|
+
the ISBN numbers:
|
137
|
+
|
138
|
+
> rec.subfield("020", "a").map{|s| s.value}
|
139
|
+
=> ["9781472214812", "1472214811"]
|
140
|
+
|
141
|
+
### Convenience methods
|
142
|
+
|
143
|
+
There are several methods to make it easier to get single fields or categories
|
144
|
+
of fields. `#mainEntry` will return whichever of the 1XX fields the record has
|
145
|
+
(as a `DataField`, not an array):
|
146
|
+
|
147
|
+
> rec.mainEntry.to_s
|
148
|
+
=> "100 1\#$aButler, Octavia Estelle$d(1947-2006).$4aut"
|
149
|
+
|
150
|
+
`#titleStatement` gets the 245 field (again, as a `DataField` and not an array):
|
151
|
+
|
152
|
+
> rec.titleStatement.value
|
153
|
+
=> "Kindred /Octavia E. Butler."
|
154
|
+
|
155
|
+
There are also methods to get an array of each of the main categories of
|
156
|
+
fields. Each of these returns an array of all the fields in the record of the
|
157
|
+
given category:
|
158
|
+
|
159
|
+
> rec.controlFields # 00X
|
160
|
+
> rec.codes # 01X-09X
|
161
|
+
> rec.titles # 20X-24X
|
162
|
+
> rec.edition # 25X-28X
|
163
|
+
> rec.description # 3XX
|
164
|
+
> rec.series # 4XX
|
165
|
+
> rec.notes # 5XX
|
166
|
+
> rec.subjects # 6XX
|
167
|
+
> rec.addedEntries # 70X-75X
|
168
|
+
> rec.linking # 76X-78X
|
169
|
+
> rec.seriesAdded # 80X-83X
|
170
|
+
> rec.holdings # 841-88X
|
171
|
+
|
172
|
+
Some common numbers have convenience methods:
|
173
|
+
|
174
|
+
> record.lccn # 010$a, String or nil
|
175
|
+
> record.isbns # 020$a, Array of Strings, or []
|
176
|
+
> record.issns # 022$a, Array of Strings, or []
|
177
|
+
|
178
|
+
### Leader
|
179
|
+
|
180
|
+
You can get the record leader:
|
181
|
+
|
182
|
+
> rec.leader
|
183
|
+
=> "00000cam a2200000Mi 4500"
|
184
|
+
|
185
|
+
## Development
|
186
|
+
|
187
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
188
|
+
|
189
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
190
|
+
|
191
|
+
## Contributing
|
192
|
+
|
193
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/seanredmond/marcxella. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
194
|
+
|
195
|
+
## License
|
196
|
+
|
197
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
198
|
+
|
199
|
+
## Code of Conduct
|
200
|
+
|
201
|
+
Everyone interacting in the Marcxella project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/seanredmond/marcxella/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "marcxella"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/marcxella.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Marcxella
|
2
|
+
# Wrapper for a collection element, which contains 0 or more record
|
3
|
+
# elements
|
4
|
+
# @since 0.1.0
|
5
|
+
class Collection
|
6
|
+
def initialize(node)
|
7
|
+
@node = node
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Array<Record>] the records in the container
|
11
|
+
def records
|
12
|
+
@node.css('record').map{|r| Record.new(r)}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Marcxella
|
2
|
+
|
3
|
+
# A control field (00X). Control fields have a value but no subfields
|
4
|
+
# @since 0.1.0
|
5
|
+
# @attr_reader [String] tag the field tag
|
6
|
+
# @attr_reader [String] value the field value
|
7
|
+
# @attr_reader [Array] For compatability. Always an empty array
|
8
|
+
# @see https://www.loc.gov/marc/bibliographic/bd00x.html
|
9
|
+
# 00X - Control Fields-General Information
|
10
|
+
#
|
11
|
+
class ControlField
|
12
|
+
attr_reader :tag, :value, :subfields
|
13
|
+
def initialize(node)
|
14
|
+
@tag = node['tag']
|
15
|
+
@value = node.text
|
16
|
+
@subfields = []
|
17
|
+
end
|
18
|
+
|
19
|
+
# a string representation of the field.
|
20
|
+
# @return [String]
|
21
|
+
def to_s
|
22
|
+
"%s %s" % [@tag, @value]
|
23
|
+
end
|
24
|
+
|
25
|
+
# For compatability. Always returns an empty array because control fields
|
26
|
+
# don't have subfields
|
27
|
+
# @return Array an empty array
|
28
|
+
def subfield(code)
|
29
|
+
@subfields
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Marcxella
|
2
|
+
class DataField
|
3
|
+
attr_reader :tag, :ind1, :ind2, :subfields
|
4
|
+
def initialize(node)
|
5
|
+
@tag = node['tag']
|
6
|
+
@ind1 = node['ind1']
|
7
|
+
@ind2 = node['ind2']
|
8
|
+
@subfields = node.css('subfield').map{|s| SubField.new(s)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def value
|
12
|
+
@subfields.map{|s| s.value}.join('')
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"%s %s%s%s" % [@tag, ind_to_s(@ind1), ind_to_s(@ind2), @subfields.join('')]
|
17
|
+
end
|
18
|
+
|
19
|
+
def subfield(code)
|
20
|
+
@subfields.select{|s| s.code == code }
|
21
|
+
end
|
22
|
+
|
23
|
+
def ind_to_s(i)
|
24
|
+
if i == ' '
|
25
|
+
return '#'
|
26
|
+
end
|
27
|
+
|
28
|
+
return i
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Marcxella
|
2
|
+
|
3
|
+
# Container for a MARC-XML document
|
4
|
+
# @since 0.1.0
|
5
|
+
# @attr_reader [Nokigiri::XML::Document] document wrapped Nokogiri document
|
6
|
+
class Document
|
7
|
+
attr_reader :document
|
8
|
+
|
9
|
+
# Constructor for Document object
|
10
|
+
# @param [Nokogiri::XML::Document, File, String] xml source
|
11
|
+
def initialize(xml)
|
12
|
+
if xml.is_a? Nokogiri::XML::Document
|
13
|
+
@document = xml
|
14
|
+
else
|
15
|
+
@document = Nokogiri::XML(xml)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Record elements
|
20
|
+
# @return [Array<Record>] array of record objects (possibly empty). If the
|
21
|
+
# document contains collection elements, returns record objects inside the
|
22
|
+
# collections
|
23
|
+
def records
|
24
|
+
@document.css('record').map{|r| Record.new(r)}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Collection elements
|
28
|
+
# @return [Array<Collection>] array of collection objects (possible empty).
|
29
|
+
def collections
|
30
|
+
@document.css('collection').map{|c| Collection.new(c)}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
module Marcxella
|
2
|
+
|
3
|
+
# Wrapper for a record element
|
4
|
+
# @since 0.1.0
|
5
|
+
# @attr_reader [Nokogiri::XML::Document] node the wrapped record element node
|
6
|
+
# @attr_reader [String] leader the record leader
|
7
|
+
class Record
|
8
|
+
attr_reader :node, :leader, :fields
|
9
|
+
def initialize(node)
|
10
|
+
@node = node
|
11
|
+
@leader = node.css('leader').text
|
12
|
+
@fields = node.css('controlfield, datafield').map{|f| objectify f}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get fields by a tag
|
16
|
+
# @param tag [String] Tag of the field to get.
|
17
|
+
# @return [Array<DataField>, Array<ControlField>] The
|
18
|
+
# return type will depend on the tag being requested.
|
19
|
+
def field(tag)
|
20
|
+
return @fields.select{|f| f.tag == tag}
|
21
|
+
end
|
22
|
+
|
23
|
+
# The control and data fields of the record
|
24
|
+
# @return [Array<ControlField, DataField>]
|
25
|
+
def fields
|
26
|
+
@node.css('controlfield, datafield').map{|f| objectify f}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Does the record include a field with a specific tag?
|
30
|
+
#
|
31
|
+
# @return [boolean] true if there is at least one control or data field
|
32
|
+
# with the specified tag.
|
33
|
+
def include?(tag, code = nil)
|
34
|
+
not field(tag, code).empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
# The record's main entry field. Every record should have one (and only
|
38
|
+
# one) of the 1XX fields (100, 110, 111, 130).
|
39
|
+
#
|
40
|
+
# @since 0.1.0
|
41
|
+
# @return [DataField]
|
42
|
+
# @see https://www.loc.gov/marc/bibliographic/bd1xx.html
|
43
|
+
# 1XX - Main Entries-General Information
|
44
|
+
def mainEntry
|
45
|
+
tag_range("100", "1XX").first
|
46
|
+
end
|
47
|
+
|
48
|
+
# The record's title statement. That is, its 245 field
|
49
|
+
#
|
50
|
+
# @since 0.1.0
|
51
|
+
# @return [DataField]
|
52
|
+
# @see https://www.loc.gov/marc/bibliographic/bd245.html
|
53
|
+
# 245 - Title Statement
|
54
|
+
def titleStatement
|
55
|
+
field("245").first
|
56
|
+
end
|
57
|
+
|
58
|
+
# The control fields (00X)
|
59
|
+
# @since 0.1.0
|
60
|
+
# @return [Array<ControlField>]
|
61
|
+
# @see https://www.loc.gov/marc/bibliographic/bd00x.html
|
62
|
+
# 00X - Control Fields-General Information
|
63
|
+
def controlFields
|
64
|
+
tag_range("001", "009")
|
65
|
+
end
|
66
|
+
|
67
|
+
# The numbers and code fields (01X-09X)
|
68
|
+
# @since 0.1.0
|
69
|
+
# @return [Array<DataField>]
|
70
|
+
# @see https://www.loc.gov/marc/bibliographic/bd01x09x.html
|
71
|
+
# 01X-09X - Numbers and Codes-General Information
|
72
|
+
def codes
|
73
|
+
tag_range("010", "09X")
|
74
|
+
end
|
75
|
+
|
76
|
+
# The title- and title-related fields (20X-24X)
|
77
|
+
# @since 0.1.0
|
78
|
+
# @return [Array<DataField>]
|
79
|
+
# @see https://www.loc.gov/marc/bibliographic/bd20x24x.html
|
80
|
+
# 20X-24X - Title and Title-Related Fields - General Information
|
81
|
+
def titles
|
82
|
+
tag_range("200", "24X2")
|
83
|
+
end
|
84
|
+
|
85
|
+
# The edition- and imprint-related fields (25X-28X)
|
86
|
+
# @since 0.1.0
|
87
|
+
# @return [Array<DataField>]
|
88
|
+
# @see https://www.loc.gov/marc/bibliographic/bd25x28x.html
|
89
|
+
# 25X-28X - Edition, Imprint, Etc. Fields-General Information
|
90
|
+
def edition
|
91
|
+
tag_range("250", "28X")
|
92
|
+
end
|
93
|
+
|
94
|
+
# The physical description fields (3XX)
|
95
|
+
# @since 0.1.0
|
96
|
+
# @return [Array<DataField>]
|
97
|
+
# @see https://www.loc.gov/marc/bibliographic/bd3xx.html
|
98
|
+
# 3XX - Physical Description, Etc. Fields - General Information
|
99
|
+
def description
|
100
|
+
tag_range("300", "399")
|
101
|
+
end
|
102
|
+
|
103
|
+
# The series statement fields (4XX)
|
104
|
+
# @since 0.1.0
|
105
|
+
# @return [Array<DataField>]
|
106
|
+
# @see https://www.loc.gov/marc/bibliographic/bd4xx.html
|
107
|
+
# 4XX - Series Statement Fields (4XX)
|
108
|
+
def series
|
109
|
+
tag_range("400", "499")
|
110
|
+
end
|
111
|
+
|
112
|
+
# The note statement fields (5XX)
|
113
|
+
# @since 0.1.0
|
114
|
+
# @return [Array<DataField>]
|
115
|
+
# @see https://www.loc.gov/marc/bibliographic/bd5xx.html
|
116
|
+
# 5XX - Note Fields - General Information
|
117
|
+
def notes
|
118
|
+
tag_range("500", "59X")
|
119
|
+
end
|
120
|
+
|
121
|
+
# The subject access fields (6XX)
|
122
|
+
# @since 0.1.0
|
123
|
+
# @return [Array<DataField>]
|
124
|
+
# @see https://www.loc.gov/marc/bibliographic/bd6xx.html
|
125
|
+
# 6XX - Subject Access Fields-General Information
|
126
|
+
def subjects
|
127
|
+
tag_range("600", "69X")
|
128
|
+
end
|
129
|
+
|
130
|
+
# The added entry fields (70X-75X)
|
131
|
+
# @since 0.1.0
|
132
|
+
# @return [Array<DataField>]
|
133
|
+
# @see https://www.loc.gov/marc/bibliographic/bd70x75x.html
|
134
|
+
# 70X-75X - Added Entry Fields - General Information
|
135
|
+
def addedEntries
|
136
|
+
tag_range("700", "75X")
|
137
|
+
end
|
138
|
+
|
139
|
+
# The linking entry fields (76X-78X)
|
140
|
+
# @since 0.1.0
|
141
|
+
# @return [Array<DataField>]
|
142
|
+
# @see https://www.loc.gov/marc/bibliographic/bd76x78x.html
|
143
|
+
# 76X-78X - Linking Entries-General Information
|
144
|
+
def linking
|
145
|
+
tag_range("760", "78X")
|
146
|
+
end
|
147
|
+
|
148
|
+
# The series added entry fields (80X-83X)
|
149
|
+
# @since 0.1.0
|
150
|
+
# @return [Array<DataField>]
|
151
|
+
# @see https://www.loc.gov/marc/bibliographic/bd80x83x.html
|
152
|
+
# 80X-83X - Series Added Entry Fields
|
153
|
+
def seriesAdded
|
154
|
+
tag_range("800", "83X")
|
155
|
+
end
|
156
|
+
|
157
|
+
# The holdings, alternate graphics, etc fields (841-88X)
|
158
|
+
# @since 0.1.0
|
159
|
+
# @return [Array<DataField>]
|
160
|
+
# @see https://www.loc.gov/marc/bibliographic/bd84188x.html
|
161
|
+
# 841-88X - Holdings, Alternate Graphics, Etc.-General Information
|
162
|
+
def holdings
|
163
|
+
tag_range("841", "88X")
|
164
|
+
end
|
165
|
+
|
166
|
+
# The Library of Congress Control Number (010$a). Only returns the $a
|
167
|
+
# subfields, nothing from the $b or $z
|
168
|
+
# @return [String] the LCCN, nil if there is none.
|
169
|
+
# @since 0.1.0
|
170
|
+
def lccn
|
171
|
+
s = subfield("010", "a")
|
172
|
+
return nil if s.empty?
|
173
|
+
s.first.value
|
174
|
+
end
|
175
|
+
|
176
|
+
# The International Standard Book Number (020$a)
|
177
|
+
# @return [Array<String>] An array of ISBNs
|
178
|
+
# @since 0.1.0
|
179
|
+
def isbns
|
180
|
+
subfield("020", "a").map{|s| s.value}
|
181
|
+
end
|
182
|
+
|
183
|
+
# The International Standard Serial Number (022$a)
|
184
|
+
# @return [Array<String>] An array of ISSNs
|
185
|
+
# @since 0.1.0
|
186
|
+
def issns
|
187
|
+
subfield("022", "a").map{|s| s.value}
|
188
|
+
end
|
189
|
+
|
190
|
+
def objectify(f)
|
191
|
+
if f.name == 'controlfield'
|
192
|
+
return ControlField.new(f)
|
193
|
+
else
|
194
|
+
return DataField.new(f)
|
195
|
+
end
|
196
|
+
|
197
|
+
raise "Wha?"
|
198
|
+
end
|
199
|
+
|
200
|
+
def tag_range(first, last)
|
201
|
+
@fields.select{|f| f.tag >= first and f.tag <= last}
|
202
|
+
end
|
203
|
+
|
204
|
+
# get a subfield from matching fields, for instance all 651$a subfields
|
205
|
+
# @param [String] tag tag to match
|
206
|
+
# @param [String] code code to match
|
207
|
+
# @return [Array<SubField>] an array of matching subfields
|
208
|
+
# @since 0.1.0
|
209
|
+
def subfield(tag, code)
|
210
|
+
field(tag).map{|f| f.subfields.select{|s| s.code == code } }.flatten
|
211
|
+
end
|
212
|
+
|
213
|
+
private :objectify, :tag_range
|
214
|
+
end
|
215
|
+
end
|
data/marcxella.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "marcxella/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "marcxella"
|
8
|
+
spec.version = Marcxella::VERSION
|
9
|
+
spec.authors = ["Sean Redmond"]
|
10
|
+
spec.email = ["github-smr@sneakemail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Little library for reading MARC-XML.}
|
13
|
+
spec.description = %q{A little library for reading MARC-XML, for when you just need to deal with it quickly.}
|
14
|
+
spec.homepage = "https://github.com/seanredmond/marcxella"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marcxella
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Redmond
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A little library for reading MARC-XML, for when you just need to deal
|
56
|
+
with it quickly.
|
57
|
+
email:
|
58
|
+
- github-smr@sneakemail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/marcxella.rb
|
74
|
+
- lib/marcxella/collection.rb
|
75
|
+
- lib/marcxella/controlfield.rb
|
76
|
+
- lib/marcxella/datafield.rb
|
77
|
+
- lib/marcxella/document.rb
|
78
|
+
- lib/marcxella/record.rb
|
79
|
+
- lib/marcxella/subfield.rb
|
80
|
+
- lib/marcxella/version.rb
|
81
|
+
- marcxella.gemspec
|
82
|
+
homepage: https://github.com/seanredmond/marcxella
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.7.6
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Little library for reading MARC-XML.
|
106
|
+
test_files: []
|