Module: Nori::CoreExt::Hash
- Defined in:
- lib/nori/core_ext/hash.rb
Instance Method Summary collapse
-
#normalize_param(key, value) ⇒ String
This key value pair as a param.
-
#to_params ⇒ String
This hash as a query string.
-
#to_xml_attributes ⇒ String
The hash as attributes for an XML tag.
Instance Method Details
#normalize_param(key, value) ⇒ String
Returns This key value pair as a param.
28 29 30 31 32 33 34 35 36 |
# File 'lib/nori/core_ext/hash.rb', line 28 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_params ⇒ String
Returns This hash as a query string.
18 19 20 |
# File 'lib/nori/core_ext/hash.rb', line 18 def to_params map { |k, v| normalize_param(k,v) }.flatten.join('&') end |
#to_xml_attributes ⇒ String
Returns The hash as attributes for an XML tag.
43 44 45 46 47 |
# File 'lib/nori/core_ext/hash.rb', line 43 def to_xml_attributes map do |k, v| %{#{k.to_s.snakecase.sub(/^(.{1,1})/) { |m| m.downcase }}="#{v}"} end.join(' ') end |