Module: Philiprehberger::HeaderKit::AcceptBuilder

Defined in:
lib/philiprehberger/header_kit/accept_builder.rb

Overview

Builds Accept header strings from structured type entries.

Class Method Summary collapse

Class Method Details

.build(types) ⇒ String

Build an Accept header string from an array of type hashes.

Parameters:

  • types (Array<Hash>)

    each with :type and optional :quality

Returns:

  • (String)

    formatted Accept header value



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/philiprehberger/header_kit/accept_builder.rb', line 11

def self.build(types)
  return '' if types.nil? || types.empty?

  parts = types.map do |entry|
    type = entry[:type]
    quality = entry[:quality]

    if quality && quality < 1.0
      "#{type};q=#{format_quality(quality)}"
    else
      type
    end
  end

  parts.join(', ')
end