Skip to content

Commit 6346e81

Browse files
committed
Add edition property to BibliographicRecord
1 parent 70d45e3 commit 6346e81

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
(Nothing yet)
9+
### Added
10+
11+
- Added edition property to BibliographicRecord.
12+
([da949e6](https://github.com/scriptotek/php-marc/commit/da949e640e86be7498f26d0e74fbb6c26bfcbce3))
1013

1114
## [2.1.0] - 2019-11-20
1215

src/BibliographicRecord.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Scriptotek\Marc\Exceptions\UnknownRecordType;
66
use Scriptotek\Marc\Fields\Classification;
7+
use Scriptotek\Marc\Fields\Edition;
78
use Scriptotek\Marc\Fields\Isbn;
89
use Scriptotek\Marc\Fields\Person;
910
use Scriptotek\Marc\Fields\Publisher;
@@ -65,10 +66,20 @@ public function getTitle()
6566
return Title::get($this);
6667
}
6768

69+
/**
70+
* Get 250 as an `Edition` object. Returns null if no such field was found.
71+
*
72+
* @return Edition
73+
*/
74+
public function getEdition()
75+
{
76+
return Edition::get($this);
77+
}
78+
6879
/**
6980
* Get 26[04]$b as a `Publisher` object. Returns null if no such field was found.
7081
*
71-
* @return Title
82+
* @return Publisher
7283
*/
7384
public function getPublisher()
7485
{

src/Fields/Edition.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Scriptotek\Marc\Fields;
4+
5+
use Scriptotek\Marc\Record;
6+
7+
class Edition extends Field implements FieldInterface
8+
{
9+
public static function get(Record $record)
10+
{
11+
foreach ($record->query('250') as $field) {
12+
return new static($field->getField());
13+
}
14+
}
15+
16+
public function __toString()
17+
{
18+
return $this->sf('a');
19+
}
20+
}

tests/data/examples/bibliographic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "The eightfold way",
55
"publisher": "W.A. Benjamin",
66
"pub_year": "1964",
7-
"edition": null,
7+
"edition": "Third edition",
88
"creators": [
99
{
1010
"type": "100",
@@ -38,4 +38,4 @@
3838
"toc": null,
3939
"summary": null,
4040
"part_of": null
41-
}
41+
}

tests/data/examples/bibliographic.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<subfield code="a">The eightfold way</subfield>
3535
<subfield code="c">Murray Gell-Mann, Yuval Ne'eman</subfield>
3636
</datafield>
37+
<datafield ind1=" " ind2=" " tag="250">
38+
<subfield code="a">Third edition</subfield>
39+
</datafield>
3740
<datafield tag="260" ind1=" " ind2=" ">
3841
<subfield code="a">New York</subfield>
3942
<subfield code="b">W.A. Benjamin</subfield>
@@ -112,4 +115,4 @@
112115
<subfield code="k">8</subfield>
113116
<subfield code="p">4</subfield>
114117
</datafield>
115-
</record>
118+
</record>

0 commit comments

Comments
 (0)