module ToReoRefinement

Public Instance Methods

to_reo() click to toggle source

type-lifting WIN32OLE objects to RobustExcelOle objects

# File lib/robust_excel_ole/general.rb, line 8
def to_reo
  General.main_classes_ole_types_and_recognising_methods.each do |classname, ole_type, methods|
    if !::OLETYPE_JRUBY_BUG
      if self.ole_type.name == ole_type
        if classname != RobustExcelOle::Range
          return classname.new(self)
        elsif self.Rows.Count == 1 && self.Columns.Count == 1
          return RobustExcelOle::Cell.new(self, self.Parent)
        else
          return RobustExcelOle::Range.new(self, self.Parent)
        end
      end
    else
      begin
        recognising_method, no_method = methods
        self.send(recognising_method)
        unless no_method.nil?
          begin
            self.send(no_method[:no_method])
            next
          rescue NoMethodError
            return classname.new(self)
          end
        end
        if classname != RobustExcelOle::Range
          return classname.new(self)
        elsif self.Rows.Count == 1 && self.Columns.Count == 1
          return RobustExcelOle::Cell.new(self, self.Parent)
        else
          return RobustExcelOle::Range.new(self, self.Parent)
        end
      rescue Java::OrgRacobCom::ComFailException => msg # NoMethodError
        #if $!.message =~ /undefined method/ &&
        #  main_classes_ole_types_and_recognising_methods.any?{ |_c, _o, recognising_method| $!.message.include?(recognising_method.to_s) }
          next
        #end
      end
    end
  end
  raise RobustExcelOle::TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
end