Skip to content

Commit

Permalink
Add edition property to BibliographicRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Jul 13, 2020
1 parent 70d45e3 commit 6346e81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

(Nothing yet)
### Added

- Added edition property to BibliographicRecord.
([da949e6](https://github.com/scriptotek/php-marc/commit/da949e640e86be7498f26d0e74fbb6c26bfcbce3))

## [2.1.0] - 2019-11-20

Expand Down
13 changes: 12 additions & 1 deletion src/BibliographicRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Scriptotek\Marc\Exceptions\UnknownRecordType;
use Scriptotek\Marc\Fields\Classification;
use Scriptotek\Marc\Fields\Edition;
use Scriptotek\Marc\Fields\Isbn;
use Scriptotek\Marc\Fields\Person;
use Scriptotek\Marc\Fields\Publisher;
Expand Down Expand Up @@ -65,10 +66,20 @@ public function getTitle()
return Title::get($this);
}

/**
* Get 250 as an `Edition` object. Returns null if no such field was found.
*
* @return Edition
*/
public function getEdition()
{
return Edition::get($this);
}

/**
* Get 26[04]$b as a `Publisher` object. Returns null if no such field was found.
*
* @return Title
* @return Publisher
*/
public function getPublisher()
{
Expand Down
20 changes: 20 additions & 0 deletions src/Fields/Edition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Scriptotek\Marc\Fields;

use Scriptotek\Marc\Record;

class Edition extends Field implements FieldInterface
{
public static function get(Record $record)
{
foreach ($record->query('250') as $field) {
return new static($field->getField());
}
}

public function __toString()
{
return $this->sf('a');
}
}
4 changes: 2 additions & 2 deletions tests/data/examples/bibliographic.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "The eightfold way",
"publisher": "W.A. Benjamin",
"pub_year": "1964",
"edition": null,
"edition": "Third edition",
"creators": [
{
"type": "100",
Expand Down Expand Up @@ -38,4 +38,4 @@
"toc": null,
"summary": null,
"part_of": null
}
}
5 changes: 4 additions & 1 deletion tests/data/examples/bibliographic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<subfield code="a">The eightfold way</subfield>
<subfield code="c">Murray Gell-Mann, Yuval Ne'eman</subfield>
</datafield>
<datafield ind1=" " ind2=" " tag="250">
<subfield code="a">Third edition</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">New York</subfield>
<subfield code="b">W.A. Benjamin</subfield>
Expand Down Expand Up @@ -112,4 +115,4 @@
<subfield code="k">8</subfield>
<subfield code="p">4</subfield>
</datafield>
</record>
</record>

0 comments on commit 6346e81

Please sign in to comment.