未定义的方法'gsub'for#

时间:2015-09-08 13:01:21

标签: java ruby jruby

我在运行脚本时遇到此错误。我对Ruby很陌生,所以请原谅我的傲慢。

我正在使用内置JRuby支持的Nuix编写脚本。

这是我的代码;

require 'benchmark'
require 'socket'
require 'rubygems'
require 'java'

java_import org.joda.time.format.DateTimeFormat

    module JSwing
      include_package javax.swing
    end

    def dropdown()

        ar = Array.new

        $current_case.getRootItems().each do set
        ar  set.guid()
        end

        names2 = JSwingJOptionPane.showInputDialog(nil, Please enter the name of the item set to export to Relativity., 
                                                            Choose item set, -1, 
                                                            nil, ar.to_java(Object), ar[0])
        if (names2.nil)
        JSwingJOptionPane.showMessageDialog(nil, No Export Set Selected)
            abort()
            end
        return names2
    end

    def writeLine (filepath, line)
        File.open(filepath, 'a') { f1 f1.puts line }
    end 

    def writeLines(filepath, lines)

        #lines.each do output
        #   puts output
        #end

        File.open(filepath, 'w') { f2 
            lines.each do line
                f2.puts line
            end

        }
    end

        def writeLinesUTF(filepath, lines)
        #lines.each do output
        #   puts output
        #end
        #progress = NxProgressBar.new(Write to file, lines.size)
        #frame = progress.ui_setup
        #frame.setVisible(true)
        count = 0
        File.open(filepath, 'wUTF-16LE') { f2 
            f2.print uFEFF
            lines.each do line
            count += 1

            if count % 1000 == 0
                #progress.update_progress(count)
            end
                f2.puts line
            end
            #frame.dispose
        }
        end





    def checknull(value)

        return value.to_s.split.join(' ').encode('UTF-16LE') unless value.nil

    end

    def checknull!(value)

        rtn = value.to_s.split.join(' ').encode('UTF-16LE') unless value.nil
        #return value.to_s.split.join(' ') unless value.nil
    end

$workset = dropdown()
$item_set_name = $workset
$arr = []
$path = DBCP BenchmarkTestUTF16.csv
sql_date = DateTimeFormatforPattern('yyyy-MM-dd HHmmss.SSS')
#sqltest()
$sharedarray = []


a = $current_case.searchUnsorted(path-guid#{$workset})
puts a.count

protocol = jdbcjtdssqlserver
#manchester SQL - 10.65.148.25
db_url = protocol + 10.65.148.251433;databaseName=Tom-Dev;selectMethod=cursor;
connection = java.sql.DriverManager.getConnection(db_url,,)




Benchmark.bm do bench

bench.report(Build Queuet) {
    count = 0
    $queue2 = Queue.new

    a.each do item
        $queue2  item
        count += 1
        if count = 10000
            break
        end
    end
    }
    puts $queue2.size

    bench.report(checknull! itemt) {

    share = Mutex.new

    #progress = NxProgressBar.new(Progress, $queue2.size)
    #frame = progress.ui_setup
    #frame.setVisible(true)
    #sharedarray = []
    threads2 = []
    #count = 0

    16.times do
      threads2  Thread.new do
        # loop until there are no more things to do

        until $queue2.empty      
          item = $queue2.pop(true) rescue nil
            if item
                begin

                    share.synchronize {

                        sqlinsert = INSERT INTO dbo.SH_TEST (item_guid,item_top_level_guid, item_parent_guid, 
                                 item_md5, item_kind, item_type, item_title, 
                                 item_file_size, item_extension, item_language, 
                                 item_name, item_failure_message, item_Process_Batch, 
                                 item_Process_Export, item_from, item_to, item_cc, item_bcc, 
                                 item_email_subject, item_path, item_case, item_has_text, 
                                 item_has_native, item_NativePath, item_TextPath, 
                                 item_conversation_index, item_lotus_thread, 
                                 item_position) 
                                 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
                        statementLog = connection.prepareStatement(sqlinsert)
                        begin
                            items_processed = 0
                            begin
                                items_processed = items_processed + 1

                                statementLog.setString(1, checknull!(item.guid))
                                statementLog.setString(2, checknull!(item.getTopLevelItem().nil  ''  item.getTopLevelItem.getGuid()))
                                statementLog.setString(3, checknull!(item.getParent().nil  ''  item.getParent.getGuid()))
                                statementLog.setString(4, checknull!(item.getDigests().getMd5()))
                                statementLog.setString(5, checknull!(item.getKind().getName()))
                                statementLog.setString(6, checknull!(item.getType().getName()))
                                statementLog.setString(7, checknull!(item.getProperties['Title']))
                                statementLog.setString(8, checknull!(item.getFileSize().to_s))
                                statementLog.setString(9, checknull!(item.getCorrectedExtension()[0..10]))
                                statementLog.setString(10, checknull!(item.getLanguage()))
                                statementLog.setString(11, checknull!(item.getName()))
                                statementLog.setString(12, checknull!(item.getProperties[FailureDetail]))
                                statementLog.setString(13, checknull!($current_case.getName() + '_' + item.getBatchLoadDetails().getBatchId()))
                                statementLog.setString(14, checknull!($current_case.getName() + '_' + $item_set_name))
                                if item.getCommunication.nil 
                                    statementLog.setString(15, checknull!(item.getProperties['From']  item.getProperties['Mapi-Sender-Email-Address']))
                                    statementLog.setString(16, checknull!(item.getProperties['To']  item.getProperties['Mapi-Display-To']  item.getProperties['SendTo']))
                                    statementLog.setString(17, checknull!(item.getProperties['Cc']  item.getProperties['Mapi-Display-Cc']  item.getProperties['CopyTo']))
                                    statementLog.setString(18, checknull!(item.getProperties['Bcc']  item.getProperties['Mapi-Display-Bcc']  item.getProperties['BlindCopyTo']))
                                else
                                    statementLog.setString(15, checknull!(item.getCommunication.getFrom().nil  ''  item.getCommunication.getFrom().join(';')))
                                    statementLog.setString(16, checknull!(item.getCommunication.getTo().nil  ''  item.getCommunication.getTo().join(';')))
                                    statementLog.setString(17, checknull!(item.getCommunication.getCc().nil  ''  item.getCommunication.getCc().join(';')))
                                    statementLog.setString(18, checknull!(item.getCommunication.getBcc().nil  ''  item.getCommunication.getBcc().join(';')))
                                end                             

                                statementLog.setString(19, checknull!(item.getProperties['Subject']  item.getProperties['Mapi-Subject']  item.getProperties['Mapi-Display-Name']))
                                statementLog.setString(20, checknull!(item.getLocalisedPathNames().join('')))
                                statementLog.setString(21, checknull!($current_case.getName())  )
                                statementLog.setString(22, checknull!(item.getTextObject().isAvailable()  1  0))
                                statementLog.setString(23, checknull!(item.getBinary().isAvailable()  1  0))
                                statementLog.setString(24, item.getBinary().isStored() == false  ''  checknull!(item.getBinary().getStoredPath()))
                                statementLog.setString(25, item.getTextObject().isStored() == false  ''  checknull!('' + Socket.gethostname + '' + item.getTextObject().getStoredPath().to_s.gsub!('','$')))
                                statementLog.setString(26, checknull!(item.getProperties['Mapi-Conversation-Index']))
                                statementLog.setString(27, checknull!(item.getProperties['$TUA'].nil  ''  item.getProperties['$TUA'].gsub('{','').split(',').first)) #Experimental!! Lotus notes conversation threading)
                                statementLog.setString(28, checknull!(item.getPosition().toArray().map{v #{v}}.join(-))) #Experimental, can be used to make relational those items from the same folder.)

                                statementLog.execute_update

                                #progress
                                if items_processed % 1000 == 0
                                    print .
                                    stdout.flush
                                end
                            rescue Exception = e
                            puts #{e}
                            p e.backtrace
                            puts statementLog
                        end
                        ensure
                        statementLog.close
                        end

                    }
                rescue
                    #puts item.guid                 
                end
            end
        end
        # when there is no more work, the thread will stop

      end
    end
    # wait until all threads have completed processing

    threads2.each do t
        t.join
    end
    bench.report(Write Lines n){
        #writeLinesUTF($path, sharedarray)
    }
    #frame.dispose

}







#end
end

return

这是不断被抛出的例外;

undefined method `gsub' for #<#<Class:0x45716032>:0x13685969>
["<script>:194:in `(root)'", "org/jruby/ext/thread/Mutex.java:149:in `synchronize'", "<script>:142:in `(root)'"]

我相信可能会被checknull函数抛出,但我无法确定。

感谢任何帮助。

由于

1 个答案:

答案 0 :(得分:4)

在使用&#39; gsub&#39;之前在字符串上尝试使用&#39; to_s&#39;就在它之前将它转换为字符串,如果它不是一个字符串。像这样:

something.to_s.gsub(...)