module Gyoku::XMLKey
Constants
- CAMELCASE
- FORMULAS
- LOWER_CAMELCASE
- UPCASE
Public Class Methods
create(key, options = {})
click to toggle source
Converts a given object
with options
to an XML key.
# 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
Private Class Methods
chop_special_characters(string)
click to toggle source
Chops special characters from the end of a given string
.
# File lib/gyoku/xml_key.rb, line 53 def chop_special_characters(string) ["!", "/"].include?(string[-1, 1]) ? string.chop : string end
key_converter(options, xml_key)
click to toggle source
Returns the formula for converting Symbol keys.
# File lib/gyoku/xml_key.rb, line 36 def key_converter(options, xml_key) return options[:key_converter] if options[:key_converter].is_a? Proc defined_key = options[:key_to_convert] if (defined_key != nil) && (defined_key == xml_key) key_converter = options[:key_converter] elsif defined_key != nil key_converter = :lower_camelcase elsif (options[:except] == xml_key) key_converter = :lower_camelcase else key_converter = options[:key_converter] || :lower_camelcase end FORMULAS[key_converter] end
qualify?(options)
click to toggle source
Returns whether to namespace all keys (elementFormDefault).
# File lib/gyoku/xml_key.rb, line 63 def qualify?(options) options[:element_form_default] == :qualified && options[:namespace] end
unqualify?(key)
click to toggle source
Returns whether to remove the namespace from a given key
.
# File lib/gyoku/xml_key.rb, line 58 def unqualify?(key) key[0, 1] == ":" end