Module: Gyoku::XMLKey

Defined in:
lib/gyoku/xml_key.rb

Constant Summary collapse

CAMELCASE =
lambda { |key| key.gsub(/\/(.?)/) { |m| "::#{m.split('').last.upcase}" }.gsub(/(?:^|_)(.)/) { |m| m.split('').last.upcase } }
LOWER_CAMELCASE =
lambda { |key| key[0].chr.downcase + CAMELCASE.call(key)[1..-1] }
UPCASE =
lambda { |key| key.upcase }
FORMULAS =
{
  :lower_camelcase => lambda { |key| LOWER_CAMELCASE.call(key) },
  :camelcase       => lambda { |key| CAMELCASE.call(key) },
  :upcase          => lambda { |key| UPCASE.call(key) },
  :none            => lambda { |key| key }
}

Class Method Summary collapse

Class Method Details

.create(key, options = {}) ⇒ Object

Converts a given object with options to an XML key.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gyoku/xml_key.rb', line 17

def create(key, options = {})
  xml_key = chop_special_characters key.to_s

  if unqualified = unqualify?(xml_key)
    xml_key = xml_key.split(":").last
  end

  xml_key = key_converter(options, xml_key).call(xml_key) if Symbol === key

  if !unqualified && qualify?(options) && !xml_key.include?(":")
    xml_key = "#{options[:namespace]}:#{xml_key}"
  end

  xml_key
end