Class: RedSnow::Headers
- Inherits:
-
KeyValueCollection
- Object
- BlueprintNode
- KeyValueCollection
- RedSnow::Headers
- 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
Instance Method Summary collapse
-
#content_type ⇒ String
The value of ‘Content-type’ header if present or nil.
-
#initialize(headers) ⇒ Headers
constructor
A new instance of Headers.
Methods inherited from KeyValueCollection
Constructor Details
#initialize(headers) ⇒ Headers
Returns a new instance of Headers.
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_type ⇒ String
Returns 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 |