class Peictt::Builder::HttpHeader

Constants

ERROR_MSG
MODIFIERS

Attributes

args[R]
headers[R]

Public Class Methods

new(arg) click to toggle source
# File lib/peictt/builder/http_header.rb, line 12
def initialize(arg)
  @args = arg
  @headers = { "Content-Type" => "text/html" }
  process_args
end

Public Instance Methods

status() click to toggle source
# File lib/peictt/builder/http_header.rb, line 18
def status
  @status || 200
end

Private Instance Methods

add_headers(headers) click to toggle source
# File lib/peictt/builder/http_header.rb, line 32
def add_headers(headers)
  @headers.merge! headers
end
json() click to toggle source
# File lib/peictt/builder/http_header.rb, line 24
def json
  @headers["Content-Type"] = "application/json"
end
process_args() click to toggle source
# File lib/peictt/builder/http_header.rb, line 47
def process_args
  if (args.size > 1) && (args[1].is_a? Hash)
    process_options args[1]
  elsif (args.size == 1) && (args[0].is_a? Hash)
    process_options args[0]
  elsif (args.size == 1) &&
        ((args[0].is_a? String) || (args[0].is_a? Symbol))
    status
  elsif (args.size > 1) && (!args[1].is_a? Hash)
    raise ArgumentError.new ERROR_MSG
  end
end
process_options(options) click to toggle source
# File lib/peictt/builder/http_header.rb, line 36
def process_options(options)
  @status = options[:status]
  options.keys.each do |key|
    if MODIFIERS.include?(key) && (key != :headers)
      send(key)
    elsif MODIFIERS.include?(key) && (key == :headers)
      add_headers options[:headers]
    end
  end
end
text() click to toggle source
# File lib/peictt/builder/http_header.rb, line 28
def text
  @headers["Content-Type"] = "text/plain"
end