module SoapEnumerator::GenericHelpers

Public Instance Methods

attributes_2_hashes(attributes) click to toggle source
# File lib/soap_enumerator/helpers/generic_helpers.rb, line 27
def attributes_2_hashes(attributes)
  attributes.values.map {|attr| {attr.name => attr.value}}.flatten
end
attributes_2_methods(element) click to toggle source

get each attribute, convert it to a singleton method. the new method's name comes from the attribute's name. (convert attr' name to snake_case) then get the method's value from the attribute's value

@param [Nokogiri::XML::NodeSet] element

@return [Array<Symbol>]

Array of symbols which actually now are singleton methods with values
# File lib/soap_enumerator/helpers/generic_helpers.rb, line 21
def attributes_2_methods(element)
  element.attributes.map do |_k, attr_v|
    define_singleton_method(to_snake_case(attr_v.name).to_sym) { attr_v.value }
  end
end
to_snake_case(string) click to toggle source
# File lib/soap_enumerator/helpers/generic_helpers.rb, line 4
def to_snake_case(string)
  string.gsub(/::/, '/')
        .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
        .gsub(/([a-z\d])([A-Z])/,'\1_\2')
        .tr("-", "_")
        .downcase
end