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(sc_header_collection_handle_payload) ⇒ Headers
constructor
A new instance of Headers.
Methods inherited from KeyValueCollection
Constructor Details
#initialize(sc_header_collection_handle_payload) ⇒ Headers
Returns a new instance of Headers.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/redsnow/blueprint.rb', line 108 def initialize(sc_header_collection_handle_payload) sc_header_collection_size = RedSnow::Binding.sc_header_collection_size(sc_header_collection_handle_payload) if sc_header_collection_size > 0 headers_size = sc_header_collection_size - 1 @collection = Array.new for index in 0..headers_size do sc_header_handle = RedSnow::Binding.sc_header_handle(sc_header_collection_handle_payload, index) @collection << Hash[:name => RedSnow::Binding.sc_header_key(sc_header_handle), :value => RedSnow::Binding.sc_header_value(sc_header_handle)] end end end |
Instance Method Details
#content_type ⇒ String
Returns the value of ‘Content-type’ header if present or nil.
102 103 104 105 |
# File 'lib/redsnow/blueprint.rb', line 102 def content_type content_type_header = @collection.detect { |header| header.has_key?(CONTENT_TYPE_HEADER_KEY) } return (content_type_header.nil?) ? nil : content_type_header[CONTENT_TYPE_HEADER_KEY] end |