module General
Constants
- CONNECT_EXCEL_JRUBY_BUG
- CONNECT_JRUBY_BUG
- COPYSHEETS_JRUBY_BUG
- ERRORMESSAGE_JRUBY_BUG
- EXPANDPATH_JRUBY_BUG
- IS_JRUBY_PLATFORM
- NetworkDrive
@private
- OLETYPE_JRUBY_BUG
- RANGES_JRUBY_BUG
- WIN32OLE_INSTANCE_METHODS
Public Class Methods
absolute_path(file)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 239 def absolute_path(file) file = file.to_path if file.respond_to?(:to_path) return file if file[0,2] == "//" file[0,2] = './' if ::EXPANDPATH_JRUBY_BUG && file =~ /[A-Z]:[^\/]/ file = File.expand_path(file) file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/ WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file) #.tr('/','\\') end
canonize(filename)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 249 def canonize(filename) raise TypeREOError, "No string given to canonize, but #{filename.inspect}" unless filename.is_a?(String) filename = hostnameshare2networkpath(filename) normalize(filename) if filename end
change_current_binding(current_object)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 266 def change_current_binding(current_object) Pry.change_current_binding(current_object) end
init_reo_for_win32ole()
click to toggle source
@private enable RobustExcelOle
methods to Win32Ole objects
# File lib/robust_excel_ole/general.rb, line 288 def init_reo_for_win32ole method_occurrences = {} main_classes_ole_types_and_recognising_methods.each do |classname, _ole_type, _recognising_method| meths = (classname.instance_methods(false) - WIN32OLE_INSTANCE_METHODS - Object.methods - Enumerable.instance_methods(false) - [:Calculation=]) meths.each do |inst_method| method_occurrences[inst_method] = method_occurrences[inst_method] ? :several_classes : classname end end method_occurrences.each do |inst_method, class_name| if WIN32OLE.method_defined?(inst_method) aliased_method = "#{inst_method}_after_reo".to_s.to_sym WIN32OLE.send(:alias_method, aliased_method, inst_method) else aliased_method = nil end if aliased_method || class_name == :several_classes WIN32OLE.send(:define_method, inst_method) do |*args, &blk| begin obj = to_reo rescue sending_method = aliased_method ? aliased_method : inst_method.capitalize return self.send(sending_method, *args, &blk) end obj.send(inst_method, *args, &blk) end else WIN32OLE.send(:define_method, inst_method) do |*args, &blk| begin obj = class_name.new(self) rescue sending_method = aliased_method ? aliased_method : inst_method.capitalize return self.send(sending_method, *args, &blk) end obj.send(inst_method, *args, &blk) end end end end
main_classes_ole_types_and_recognising_methods()
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 271 def main_classes_ole_types_and_recognising_methods [[RobustExcelOle::Range , 'Range' , :Row], [RobustExcelOle::Worksheet , '_Worksheet' , :UsedRange], [RobustExcelOle::Workbook , '_Workbook' , :FullName], [RobustExcelOle::Excel , '_Application', :Hwnd], [RobustExcelOle::ListObject, 'ListObject' , :ListRows], [RobustExcelOle::ListRow , 'ListRow' , [:Creator, :no_method => :Row]]] end
normalize(path)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 256 def normalize(path) return unless path path = path.gsub('/./', '/') + '/' path = path.gsub(/[\/\\]+/, '/') nil while path.gsub!(/(\/|^)(?!\.\.?)([^\/]+)\/\.\.\//, '\1') path = path.chomp('/') path end
Private Instance Methods
absolute_path(file)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 239 def absolute_path(file) file = file.to_path if file.respond_to?(:to_path) return file if file[0,2] == "//" file[0,2] = './' if ::EXPANDPATH_JRUBY_BUG && file =~ /[A-Z]:[^\/]/ file = File.expand_path(file) file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/ WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file) #.tr('/','\\') end
canonize(filename)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 249 def canonize(filename) raise TypeREOError, "No string given to canonize, but #{filename.inspect}" unless filename.is_a?(String) filename = hostnameshare2networkpath(filename) normalize(filename) if filename end
change_current_binding(current_object)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 266 def change_current_binding(current_object) Pry.change_current_binding(current_object) end
init_reo_for_win32ole()
click to toggle source
@private enable RobustExcelOle
methods to Win32Ole objects
# File lib/robust_excel_ole/general.rb, line 288 def init_reo_for_win32ole method_occurrences = {} main_classes_ole_types_and_recognising_methods.each do |classname, _ole_type, _recognising_method| meths = (classname.instance_methods(false) - WIN32OLE_INSTANCE_METHODS - Object.methods - Enumerable.instance_methods(false) - [:Calculation=]) meths.each do |inst_method| method_occurrences[inst_method] = method_occurrences[inst_method] ? :several_classes : classname end end method_occurrences.each do |inst_method, class_name| if WIN32OLE.method_defined?(inst_method) aliased_method = "#{inst_method}_after_reo".to_s.to_sym WIN32OLE.send(:alias_method, aliased_method, inst_method) else aliased_method = nil end if aliased_method || class_name == :several_classes WIN32OLE.send(:define_method, inst_method) do |*args, &blk| begin obj = to_reo rescue sending_method = aliased_method ? aliased_method : inst_method.capitalize return self.send(sending_method, *args, &blk) end obj.send(inst_method, *args, &blk) end else WIN32OLE.send(:define_method, inst_method) do |*args, &blk| begin obj = class_name.new(self) rescue sending_method = aliased_method ? aliased_method : inst_method.capitalize return self.send(sending_method, *args, &blk) end obj.send(inst_method, *args, &blk) end end end end
main_classes_ole_types_and_recognising_methods()
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 271 def main_classes_ole_types_and_recognising_methods [[RobustExcelOle::Range , 'Range' , :Row], [RobustExcelOle::Worksheet , '_Worksheet' , :UsedRange], [RobustExcelOle::Workbook , '_Workbook' , :FullName], [RobustExcelOle::Excel , '_Application', :Hwnd], [RobustExcelOle::ListObject, 'ListObject' , :ListRows], [RobustExcelOle::ListRow , 'ListRow' , [:Creator, :no_method => :Row]]] end
normalize(path)
click to toggle source
@private
# File lib/robust_excel_ole/general.rb, line 256 def normalize(path) return unless path path = path.gsub('/./', '/') + '/' path = path.gsub(/[\/\\]+/, '/') nil while path.gsub!(/(\/|^)(?!\.\.?)([^\/]+)\/\.\.\//, '\1') path = path.chomp('/') path end