Module: Nori::CoreExt::Hash

Defined in:
lib/nori/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#normalize_param(key, value) ⇒ String

Returns This key value pair as a param.

Examples:

normalize_param(:name, “Bob Jones”) #=> “name=Bob%20Jones”

Parameters:

  • key (Object)

    The key for the param.

  • value (Object)

    The value for the param.

Returns:

  • (String)

    This key value pair as a param


13
14
15
16
17
18
19
20
21
# File 'lib/nori/core_ext/hash.rb', line 13

def normalize_param(key, value)
  if value.is_a?(Array)
    normalize_array_params(key, value)
  elsif value.is_a?(Hash)
    normalize_hash_params(key, value)
  else
    normalize_simple_type_params(key, value)
  end
end

#to_xml_attributesString

Returns The hash as attributes for an XML tag.

Examples:

{ :one => 1, "two"=>"TWO" }.to_xml_attributes  #=> 'one="1" two="TWO"'

Returns:

  • (String)

    The hash as attributes for an XML tag.


28
29
30
31
32
# File 'lib/nori/core_ext/hash.rb', line 28

def to_xml_attributes
  map do |k, v|
    %{#{k.to_s.snakecase.sub(/^(.{1,1})/) { |m| m.downcase }}="#{v}"}
  end.join(' ')
end