class Quickbase::Helper

Public Class Methods

generate_fields(fields) click to toggle source
   # File lib/classes/helper.rb
17 def self.generate_fields(fields)
18   fields.map do |key,value|
19     attr_name = (key =~ /^[-+]?[0-9]+$/) ? 'fid' : 'name'
20     "<field #{attr_name}=#{key.to_s.encode(xml: :attr)}>#{value.to_s.encode(xml: :text)}</field>"
21   end
22 end
generate_xml(xml_input) click to toggle source
   # File lib/classes/helper.rb
11 def self.generate_xml(xml_input)
12   # xml_input is an array of xml strings
13   # you can use hash_to_xml to generate it
14   Nokogiri::XML("<qdbapi>#{xml_input.join}</qdbapi>")
15 end
hash_to_xml(my_hash) click to toggle source
  # File lib/classes/helper.rb
3 def self.hash_to_xml(my_hash)
4   my_hash.map do |k,v|
5     key = k.to_s.encode(xml: :text)
6     value = v.to_s.encode(xml: :text)
7     "<#{key}>#{value}</#{key}>"
8   end
9 end