Class: LinkHeaderParser::LinkHeadersCollection
- Inherits:
-
Object
- Object
- LinkHeaderParser::LinkHeadersCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/link_header_parser/link_headers_collection.rb
Instance Attribute Summary collapse
-
#headers ⇒ Array<String>
readonly
The
Array
of HTTP Link headers used to create this LinkHeadersCollection.
Instance Method Summary collapse
-
#group_by_relation_type ⇒ Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}
Retrieve a
Hash
of this collection’s LinkHeaders grouped by their relation type(s). -
#initialize(*headers, base:) ⇒ LinkHeadersCollection
constructor
Parse an array of HTTP Link headers.
- #inspect ⇒ String
-
#relation_types ⇒ Array<String>
Retrieve a unique sorted
Array
of this collection’s LinkHeader relation types. -
#to_ary ⇒ Array<Hash>
(also: #to_a)
Return an
Array
representation of this LinkHeadersCollection.
Constructor Details
#initialize(*headers, base:) ⇒ LinkHeadersCollection
Parse an array of HTTP Link headers.
21 22 23 24 25 26 27 28 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 21 def initialize(*headers, base:) # rubocop:disable Performance/ChainArrayAllocation @headers = headers.to_ary.flatten.map(&:to_str) # rubocop:enable Performance/ChainArrayAllocation @base = base.to_str push(*distinct_link_headers) end |
Instance Attribute Details
#headers ⇒ Array<String> (readonly)
The Array
of HTTP Link headers used to create this LinkHeaderParser::LinkHeadersCollection.
15 16 17 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 15 def headers @headers end |
Instance Method Details
#group_by_relation_type ⇒ Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}
Retrieve a Hash
of this collection’s LinkHeaderParser::LinkHeaders grouped by their relation type(s).
34 35 36 37 38 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 34 def group_by_relation_type relation_types.to_h do |relation_type| [relation_type.to_sym, select_by_relation_type(relation_type)] end end |
#inspect ⇒ String
41 42 43 44 45 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 41 def inspect "#<#{self.class.name}:#{format("%#0x", object_id)} " \ "headers: #{headers.inspect}, " \ "relation_types: #{relation_types.inspect}>" end |
#relation_types ⇒ Array<String>
Retrieve a unique sorted Array
of this collection’s LinkHeaderParser::LinkHeader relation types.
51 52 53 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 51 def relation_types @relation_types ||= Set.new(flat_map(&:relation_types)).to_a.sort end |
#to_ary ⇒ Array<Hash> Also known as: to_a
Return an Array
representation of this LinkHeaderParser::LinkHeadersCollection.
60 61 62 |
# File 'lib/link_header_parser/link_headers_collection.rb', line 60 def to_ary map(&:to_hash) end |