Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #145 from anybox/issn-fields
Browse files Browse the repository at this point in the history
ISSN title and number
  • Loading branch information
edsu authored Dec 10, 2019
2 parents 180f8da + f6a8b15 commit cebd0f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ ANSI Common Lisp /

A `pymarc.Record` object has a few handy methods like `title` for getting at
bits of a bibliographic record, others include: `author`, `isbn`, `subjects`,
`location`, `notes`, `physicaldescription`, `publisher`, `pubyear`. But
really, to work with MARC data you need to understand the numeric field tags
and subfield codes that are used to designate various bits of information. There
is a lot more hiding in a MARC record than these methods provide access to.
For example the `title` method extracts the information from the `245` field,
subfields `a` and `b`. You can access `245a` like so:
`location`, `notes`, `physicaldescription`, `publisher`, `pubyear`, `issn`,
`issn_title`. But really, to work with MARC data you need to understand the
numeric field tags and subfield codes that are used to designate various bits
of information. There is a lot more hiding in a MARC record than these methods
provide access to. For example the `title` method extracts the information from
the `245` field, subfields `a` and `b`. You can access `245a` like so:

```python
print(record['245']['a'])
Expand Down
26 changes: 25 additions & 1 deletion pymarc/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def as_json(self, **kwargs):

def title(self):
"""
Returns the title of the record (245 $a an $b).
Returns the title of the record (245 $a and $b).
"""
try:
title = self['245']['a']
Expand All @@ -432,6 +432,21 @@ def title(self):
pass
return title

def issn_title(self):
"""
Returns the key title of the record (222 $a and $b).
"""
try:
title = self['222']['a']
except TypeError:
title = None
if title:
try:
title += " " + self['222']['b']
except TypeError:
pass
return title

def isbn(self):
"""
Returns the first ISBN in the record or None if one is not
Expand All @@ -451,6 +466,15 @@ def isbn(self):
pass
return None

def issn(self):
"""
Returns the ISSN number [022]['a'] in the record or None
"""
try:
return self['022']['a']
except TypeError:
return None

def sudoc(self):
"""
Returns a Superintendent of Documents (SuDoc) classification number
Expand Down
23 changes: 23 additions & 0 deletions test/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ def test_title(self):
subfields=['a', "Farghin"]))
self.assertEqual(record.title(), "Farghin")

def test_issn_title(self):
record = Record()
self.assertEqual(record.issn_title(), None)
record.add_field(Field('222', ["", ""],
subfields=['a', 'Foo :', 'b', 'bar']))
self.assertEqual(record.issn_title(), 'Foo : bar')

record = Record()
record.add_field(Field('222', ["", ""],
subfields=['a', "Farghin"]))
self.assertEqual(record.issn_title(), "Farghin")

record = Record()
record.add_field(Field('222', ["", ""],
subfields=['b', "bar"]))
self.assertEqual(record.issn_title(), None)

def test_isbn(self):
record = Record()
self.assertEqual(record.isbn(), None)
Expand All @@ -133,6 +150,12 @@ def test_isbn(self):
record.add_field(Field('020', [' ', ' '], subfields=['a', '006073132X']))
self.assertEqual(record.isbn(), '006073132X')

def test_issn(self):
record = Record()
self.assertEqual(record.issn(), None)
record.add_field(Field(tag="022", indicators=["0", ""], subfields=["a", "0395-2037"]))
self.assertEqual(record.issn(), '0395-2037')

def test_multiple_isbn(self):
with open('test/multi_isbn.dat', 'rb') as fh:
reader = MARCReader(fh)
Expand Down

0 comments on commit cebd0f0

Please sign in to comment.