Module: Gyoku::XMLKey
- Defined in:
- lib/gyoku/xml_key.rb
Constant Summary collapse
- CAMELCASE =
lambda { |key| key.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } }
- LOWER_CAMELCASE =
lambda { |key| key[0].chr.downcase + CAMELCASE.call(key)[1..-1] }
- FORMULAS =
{ :lower_camelcase => lambda { |key| LOWER_CAMELCASE.call(key) }, :camelcase => lambda { |key| CAMELCASE.call(key) }, :none => lambda { |key| key } }
Class Method Summary collapse
-
.create(key, options = {}) ⇒ Object
Converts a given
object
withoptions
to an XML key. -
.symbol_converter ⇒ Object
Returns the formula for converting Symbol keys.
-
.symbol_converter=(formula) ⇒ Object
Sets the
formula
for converting Symbol keys.
Class Method Details
.create(key, options = {}) ⇒ Object
Converts a given object
with options
to an XML key.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gyoku/xml_key.rb', line 15 def create(key, = {}) xml_key = chop_special_characters key.to_s if unqualified = unqualify?(xml_key) xml_key = xml_key.split(":").last end xml_key = symbol_converter.call(xml_key) if Symbol === key if !unqualified && qualify?() && !xml_key.include?(":") xml_key = "#{[:namespace]}:#{xml_key}" end xml_key end |
.symbol_converter ⇒ Object
Returns the formula for converting Symbol keys.
32 33 34 |
# File 'lib/gyoku/xml_key.rb', line 32 def symbol_converter @symbol_converter ||= FORMULAS[:lower_camelcase] end |
.symbol_converter=(formula) ⇒ Object
Sets the formula
for converting Symbol keys. Accepts one of FORMULAS
of an object responding to :call
.
38 39 40 41 42 43 |
# File 'lib/gyoku/xml_key.rb', line 38 def symbol_converter=(formula) formula = FORMULAS[formula] unless formula.respond_to? :call raise ArgumentError, "Invalid symbol_converter formula" unless formula @symbol_converter = formula end |