class BackpackTF::Response

Public Class Methods

hash_keys_to_sym(hash) click to toggle source

checks the data type of the keys of a Hash object if the key is a String, then changes it to a Symbol otherwise, leaves it as is

# File lib/backpack_tf/response.rb, line 41
def self.hash_keys_to_sym hash
  hash.each_pair.inject({}) do |new_hash, (key, val)|
    unless key.class == String
      new_hash[key] = val
    else
      new_hash[key.to_sym] = val
    end
    new_hash
  end
end
interface() click to toggle source
# File lib/backpack_tf/response.rb, line 10
def self.interface; @interface; end
response() click to toggle source
# File lib/backpack_tf/response.rb, line 35
def self.response
end
responses(key_val = nil) click to toggle source
# File lib/backpack_tf/response.rb, line 16
def self.responses key_val = nil
  unless key_val.nil?
    key_val = { key_val => nil } unless key_val.class == Hash
    key = key_val.keys.first
    val = key_val.values.first

    if val.nil?
      @responses[key]
    elsif key == :reset && val == :confirm
      @responses = {}
    else
      @responses[key] = hash_keys_to_sym(val)
    end

  end

  @responses
end
to_sym() click to toggle source
# File lib/backpack_tf/response.rb, line 12
def self.to_sym
  self.name.to_sym
end

Private Instance Methods

check_attr_keys(attr) click to toggle source

PRIVATE INSTANCE METHODS

# File lib/backpack_tf/response.rb, line 56
def check_attr_keys attr
  raise TypeError, 'pass in a Hash object' unless attr.class == Hash 

  unless attr.keys.all? { |k| k.class == String }
    raise TypeError, 'all keys must be String object'
  end

  self.class.hash_keys_to_sym(attr)
end