Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 6a478ed

Browse files
committed
Add #to_ary/#to_a method to LinkHeadersCollection
1 parent 0b5707c commit 6a478ed

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

lib/link_header_parser/link_headers_collection.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def relation_types
5050
@relation_types ||= flat_map(&:relation_types).uniq.sort
5151
end
5252

53+
# @see LinkHeader#to_hash
54+
#
55+
# @return [Array<Hash>}>]
56+
def to_ary
57+
map(&:to_hash)
58+
end
59+
60+
alias to_a to_ary
61+
5362
private
5463

5564
attr_reader :base
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
describe LinkHeaderParser::LinkHeadersCollection, '#to_ary' do
4+
subject(:link_headers_collection) { described_class.new(headers, base: 'https://example.com') }
5+
6+
let(:headers) { ['</1>; rel="next"'] }
7+
8+
it 'returns an Array' do
9+
results = [
10+
{
11+
context_string: '/1',
12+
context_uri: 'https://example.com/1',
13+
link_parameters: { rel: ['next'] },
14+
relation_types: ['next'],
15+
relations_string: 'next',
16+
target_string: '/1',
17+
target_uri: 'https://example.com/1'
18+
}
19+
]
20+
21+
expect(link_headers_collection.to_ary).to eq(results)
22+
end
23+
end

0 commit comments

Comments
 (0)