Class: REXML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/QuickBaseClient.rb

Overview

This enables finding XML elements recursively using Ruby method syntax

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *method_args) ⇒ Object



4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
# File 'lib/QuickBaseClient.rb', line 4822

def method_missing(method_name,*method_args)
  ret = nil 
  if elements
     if method_args and method_args.length > 0
        if method_args[0].length > 1
           searchProc = proc { |e| 
              if e.is_a?(REXML::Element) and e.name == method_name.to_s and e.attributes
                if e.attributes[method_args[0][0].to_s] and e.attributes[method_args[0][0].to_s] == method_args[0][1].to_s
                   ret = e 
                end
              end  
           }
        else  
           searchProc = proc { |e| 
              if e.is_a?(REXML::Element) and e.name == method_name.to_s and e.attributes
                if e.attributes["id"] and e.attributes["id"] == method_args[0][0].to_s
                   ret = e 
                end
                if ret.nil? and e.attributes["name"] and e.attributes["name"] == method_args[0][0].to_s
                  ret = e
                end  
              end  
           }
        end   
     else
        searchProc = proc { |e| 
           if e.is_a?(REXML::Element) and e.name == method_name.to_s 
             ret = e 
           end  
        }
     end
  end 
  processChildElements( self, false, searchProc ) 
  if ret and !ret.has_elements? and ret.has_text?
     ret = ret.text.dup 
  end
  ret
end

Instance Method Details

#processChildElements(element, leafElementsOnly, block) ⇒ Object



4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
# File 'lib/QuickBaseClient.rb', line 4861

def processChildElements( element, leafElementsOnly, block )
    if element
       if element.is_a?( Array )
          element.each{ |e| processChildElements( e, leafElementsOnly, block ) }
       elsif element.is_a?( REXML::Element ) and element.has_elements?
          block.call( element ) if not leafElementsOnly
          element.each{ |e|
             if e.is_a?( REXML::Element ) and e.has_elements?
               processChildElements( e, leafElementsOnly, block )
             else
               block.call( e )
             end
          }
       end
     end
end