Class: RedSnow::Headers

Inherits:
KeyValueCollection show all
Defined in:
lib/redsnow/blueprint.rb

Overview

Headers collection Blueprint AST node

represents 'headers section'

Constant Summary collapse

CONTENT_TYPE_HEADER_KEY =

HTTP ‘Content-Type’ header

:'Content-Type'

Instance Attribute Summary

Attributes inherited from KeyValueCollection

#collection

Instance Method Summary collapse

Methods inherited from KeyValueCollection

#[], #filter_collection

Constructor Details

#initialize(headers) ⇒ Headers

Returns a new instance of Headers.

Parameters:

  • headers (json)


114
115
116
117
118
119
120
121
122
# File 'lib/redsnow/blueprint.rb', line 114

def initialize(headers)
  @collection = []

  return if headers.nil?

  headers.each do |item|
    @collection << Hash[name: item['name'], value: item['value']]
  end
end

Instance Method Details

#content_typeString

Returns the value of ‘Content-type’ header if present or nil.

Returns:

  • (String)

    the value of ‘Content-type’ header if present or nil



108
109
110
111
# File 'lib/redsnow/blueprint.rb', line 108

def content_type
  content_type_header = @collection.find { |header| header.key?(CONTENT_TYPE_HEADER_KEY) }
  (content_type_header.nil?) ? nil : content_type_header[CONTENT_TYPE_HEADER_KEY]
end