Module: Crack::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/crack/util.rb

Instance Method Summary collapse

Instance Method Details

#snake_case(str) ⇒ Object



3
4
5
6
7
# File 'lib/crack/util.rb', line 3

def snake_case(str)
  return str.downcase if str =~ /^[A-Z]+$/
  str.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
  return $+.downcase
end

#to_xml_attributes(hash) ⇒ Object



9
10
11
12
13
# File 'lib/crack/util.rb', line 9

def to_xml_attributes(hash)
  hash.map do |k,v|
    %{#{Crack::Util.snake_case(k.to_s).sub(/^(.{1,1})/) { |m| m.downcase }}="#{v.to_s.gsub('"', '"')}"}
  end.join(' ')
end