Class: Atmos::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/atmos/util.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.hash2header(value) ⇒ Object

Utility method to convert to a standard header value.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/atmos/util.rb', line 26

def self.hash2header(value)
   return nil if (value.nil?)
   raise Atmos::Exceptions::ArgumentException, "The 'value' parameter must be a Hash" if (!value.kind_of?(Hash))

   rv = ""
   if (!value.nil?)
      value.each do |k,v|
         rv += "#{k}=#{v}, "
      end
   end

   rv[0..-3]
end

.header2hash(value) ⇒ Object

Utility method to convert from a standard Atmos key/value pair return header.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/atmos/util.rb', line 7

def self.header2hash(value)
   return nil if (value.nil?)
   raise Atmos::Exceptions::ArgumentException, "The 'value' parameter must be a String" if (!value.kind_of?(String))
   
   rv = {}
   if (!value.nil?)
      value.split(',').each do |elt|
         key,val = elt.split('=')
         rv[key.strip] = val.nil? ? "" : val.strip
      end
   end

   rv
end