fieldhand 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67cb8ee7c5ff120c78181ef597a9f2ea46ed4e51
4
- data.tar.gz: c83dbeb7abe6832c9e2b65fef55689c195c63805
3
+ metadata.gz: 49c63105b6f0895f33b4efdff65a657f4b18e7bb
4
+ data.tar.gz: 824b068c57fdf22120f0f0a49d88e3cf73d1bc3d
5
5
  SHA512:
6
- metadata.gz: b5adbfea0e91229dce93d0e95a4daca0d206cb7746875f956c912e4934170b152e8afd3719ab851190a7f5c57a1b3f852db14b0f73a06aaffda9ad29ca09ad4a
7
- data.tar.gz: 667cc59bb4b785d383eeb3314483bc3a05ba66ada5843d27d3998e2d75baf0605ea35de2cc83949bafaf31115a2389b8975bf1523bc66b69ee7b6effb996ba3c
6
+ metadata.gz: ac9af26d76794bc1a1578df816b5e69fb82f151623a28d448a9446f54d2f3536ffad6dce0b8a1d29713d5d19beefda50689093472e93663cf3f2a2ebc66c4208
7
+ data.tar.gz: 2211e6803c30a037d7b5a34ba42b6005eddc50536eaa4a2bc428e245d33fb272a78f021561f1d77bc0efeb2e12d0c9eac48fbb93437775304c446d02d5105b99
data/README.md CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  A Ruby library for harvesting metadata from [OAI-PMH](https://www.openarchives.org/OAI/openarchivesprotocol.html) repositories.
4
4
 
5
- **Current version:** 0.5.0
5
+ **Current version:** 0.6.0
6
6
  **Supported Ruby versions:** 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2
7
7
 
8
8
  ## Installation
9
9
 
10
10
  ```
11
- gem install fieldhand -v '~> 0.5'
11
+ gem install fieldhand -v '~> 0.6'
12
12
  ```
13
13
 
14
14
  Or, in your `Gemfile`:
15
15
 
16
16
  ```ruby
17
- gem 'fieldhand', '~> 0.5'
17
+ gem 'fieldhand', '~> 0.6'
18
18
  ```
19
19
 
20
20
  ## Usage
@@ -49,7 +49,7 @@ repository.get('oai:www.example.com:12345')
49
49
  * [`#sets`](#fieldhandrepositorysets)
50
50
  * [`#records([arguments])`](#fieldhandrepositoryrecordsarguments)
51
51
  * [`#identifiers([arguments])`](#fieldhandrepositoryidentifiersarguments)
52
- * [`#get(identifier[, arguments])`](#fieldhandgetidentifier-arguments)
52
+ * [`#get(identifier[, arguments])`](#fieldhandrepositorygetidentifier-arguments)
53
53
  * [`Fieldhand::Identify`](#fieldhandidentify)
54
54
  * [`#name`](#fieldhandidentifyname)
55
55
  * [`#base_url`](#fieldhandidentifybase_url)
@@ -77,6 +77,7 @@ repository.get('oai:www.example.com:12345')
77
77
  * [`#identifier`](#fieldhandrecordidentifier)
78
78
  * [`#datestamp`](#fieldhandrecorddatestamp)
79
79
  * [`#sets`](#fieldhandrecordsets)
80
+ * [`#to_xml`](#fieldhandrecordto_xml)
80
81
  * [`#metadata`](#fieldhandrecordmetadata)
81
82
  * [`#about`](#fieldhandrecordabout)
82
83
  * [`#response_date`](#fieldhandrecordresponse_date)
@@ -437,6 +438,15 @@ repository.records.first.sets
437
438
 
438
439
  Return an `Array` of `String` [set specs](#fieldhandsetspec) indicating set memberships of this record.
439
440
 
441
+ #### `Fieldhand::Record#to_xml`
442
+
443
+ ```ruby
444
+ repository.records.first.to_xml
445
+ #=> "<record><metadata>...</metadata><record>"
446
+ ```
447
+
448
+ Return the record as a `String` of XML.
449
+
440
450
  #### `Fieldhand::Record#metadata`
441
451
 
442
452
  ```ruby
@@ -540,13 +550,13 @@ Return the time and date that the response was sent.
540
550
 
541
551
  An error (descended from `StandardError`) to represent any network issues encountered during interaction with the repository. Any underlying exception is exposed in Ruby 2.1 onwards through [`Exception#cause`](https://ruby-doc.org/core-2.1.0/Exception.html#method-i-cause).
542
552
 
543
- #### `Fieldhand::ResponseError`
553
+ ### `Fieldhand::ResponseError`
544
554
 
545
- An error (descended from `NetworkError`) to represent any issues in the response from the repository.
546
- If the HTTP request is not successful (returning a status code other than 200),
555
+ An error (descended from `NetworkError`) to represent any issues in the response from the repository.
556
+ If the HTTP request is not successful (returning a status code other than 200),
547
557
  a `ResponseError` exception will be raised containing the error message and the response object.
548
558
 
549
- ##### Fieldhand::ResponseError#response
559
+ #### `Fieldhand::ResponseError#response`
550
560
 
551
561
  ```ruby
552
562
  begin
@@ -559,11 +569,15 @@ rescue Fieldhand::ResponseError => e
559
569
  end
560
570
  ```
561
571
 
562
- Returns the unsuccessful `Net::HTTPResponse` that caused this error or `nil` if no response was available.
572
+ Returns the unsuccessful
573
+ [`Net::HTTPResponse`](https://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTPResponse.html)
574
+ that caused this error.
563
575
 
564
576
  ### `Fieldhand::ProtocolError`
565
577
 
566
- The parent error class (descended from `StandardError`) for any errors returned by a repository as defined in the [protocol's Error and Exception Conditions](https://www.openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions).
578
+ The parent error class (descended from `StandardError`) for any errors returned
579
+ by a repository as defined in the [protocol's Error and Exception
580
+ Conditions](https://www.openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions).
567
581
 
568
582
  This can be used to rescue all the following child error types.
569
583
 
@@ -45,11 +45,16 @@ module Fieldhand
45
45
  header.sets
46
46
  end
47
47
 
48
+ # Return this whole item as a string
49
+ def to_xml
50
+ Ox.dump(element, :encoding => 'utf-8')
51
+ end
52
+
48
53
  # Return the single manifestation of the metadata of this item as a string, if present.
49
54
  #
50
55
  # As metadata can be in any format, Fieldhand does not attempt to parse it but leave that to the user.
51
56
  def metadata
52
- @metadata ||= element.locate('metadata[0]').map { |metadata| Ox.dump(metadata) }.first
57
+ @metadata ||= element.locate('metadata[0]').map { |metadata| Ox.dump(metadata, :encoding => 'utf-8') }.first
53
58
  end
54
59
 
55
60
  # Return any about elements describing the metadata of this record as an array of strings.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'fieldhand/record'
2
4
  require 'ox'
3
5
 
@@ -33,6 +35,46 @@ module Fieldhand
33
35
 
34
36
  expect(record.metadata).to eq("\n<metadata>Foo</metadata>\n")
35
37
  end
38
+
39
+ it 'returns the metadata with unicode characters as a string' do
40
+ element = ::Ox.parse('<record><metadata>ψFooϨ</metadata></record>')
41
+ record = described_class.new(element)
42
+
43
+ expect(record.metadata).to eq("\n<metadata>ψFooϨ</metadata>\n")
44
+ end
45
+ end
46
+
47
+ describe '#to_xml' do
48
+ it 'returns the whole element even if there is no metadata as a string' do
49
+ element = ::Ox.parse('<record/>')
50
+ record = described_class.new(element)
51
+
52
+ expect(record.to_xml).to eq("\n<record/>\n")
53
+ end
54
+
55
+ it 'returns the whole element as a string' do
56
+ element = ::Ox.parse("<record><metadata>Foo</metadata></record>")
57
+ record = described_class.new(element)
58
+
59
+ expect(record.to_xml).to eq(<<-XML)
60
+
61
+ <record>
62
+ <metadata>Foo</metadata>
63
+ </record>
64
+ XML
65
+ end
66
+
67
+ it 'returns the whole element with unicode characters as a string' do
68
+ element = ::Ox.parse("<record><metadata>ψFooϨ</metadata></record>")
69
+ record = described_class.new(element)
70
+
71
+ expect(record.to_xml).to eq(<<-XML)
72
+
73
+ <record>
74
+ <metadata>ψFooϨ</metadata>
75
+ </record>
76
+ XML
77
+ end
36
78
  end
37
79
 
38
80
  describe '#about' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fieldhand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-07-11 00:00:00.000000000 Z
13
+ date: 2017-07-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ox