From 6346e810127f72a8bba387dbff3cf1e8651c74b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Michael=20O=2E=20Hegg=C3=B8?= Date: Tue, 14 Jul 2020 00:16:54 +0200 Subject: [PATCH] Add edition property to BibliographicRecord --- CHANGELOG.md | 5 ++++- src/BibliographicRecord.php | 13 ++++++++++++- src/Fields/Edition.php | 20 ++++++++++++++++++++ tests/data/examples/bibliographic.json | 4 ++-- tests/data/examples/bibliographic.xml | 5 ++++- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/Fields/Edition.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 882df6d..c431b53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/BibliographicRecord.php b/src/BibliographicRecord.php index 4b581de..5caa342 100644 --- a/src/BibliographicRecord.php +++ b/src/BibliographicRecord.php @@ -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; @@ -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() { diff --git a/src/Fields/Edition.php b/src/Fields/Edition.php new file mode 100644 index 0000000..7bcd2b9 --- /dev/null +++ b/src/Fields/Edition.php @@ -0,0 +1,20 @@ +query('250') as $field) { + return new static($field->getField()); + } + } + + public function __toString() + { + return $this->sf('a'); + } +} diff --git a/tests/data/examples/bibliographic.json b/tests/data/examples/bibliographic.json index 55ab449..4798490 100644 --- a/tests/data/examples/bibliographic.json +++ b/tests/data/examples/bibliographic.json @@ -4,7 +4,7 @@ "title": "The eightfold way", "publisher": "W.A. Benjamin", "pub_year": "1964", - "edition": null, + "edition": "Third edition", "creators": [ { "type": "100", @@ -38,4 +38,4 @@ "toc": null, "summary": null, "part_of": null -} \ No newline at end of file +} diff --git a/tests/data/examples/bibliographic.xml b/tests/data/examples/bibliographic.xml index 832c09f..253c62c 100644 --- a/tests/data/examples/bibliographic.xml +++ b/tests/data/examples/bibliographic.xml @@ -34,6 +34,9 @@ The eightfold way Murray Gell-Mann, Yuval Ne'eman + + Third edition + New York W.A. Benjamin @@ -112,4 +115,4 @@ 8 4 - \ No newline at end of file +