Ruby:用存储过程清理我的代码?

时间:2015-11-23 19:29:24

标签: mysql ruby

这是我的第一个ruby脚本。我想清理一下。我如何将所有以下nessus_scans.insert()参数存储到变量中以减少代码中的重复行?我想将:Id => "", :scan_title => ""等全部存储到此变量中,然后执行nessus_scans.insert(myvariable)之类的操作。此查询在代码中使用了大约5次,这就是我想简化它的原因。谢谢!

nessus_scans.insert(:Id => "",
      :scan_title => "#{scan.title}", 
      :hostname => "#{host.hostname}",
      :host_ip => "#{host.ip}",
      :mac_addr => "#{host.mac_addr}",
      :netbios_name => "#{host.netbios_name}",
      :open_ports => "#{host.ports.map(&:inspect).join(', ').tr('"', '')}",
      :operating_system => "#{host.operating_system}",
      :start_time => "#{host.start_time}",
      :stop_time => "#{host.stop_time}",
      :runtime => "#{host.runtime}",
      :cve => "#{event.cve}",
      :cvss_base_Score => "#{event.cvss_base_score}",
      :description => "#{event.description}",
      :family => "#{event.family}",
      :plugin_id => "#{event.plugin_id}",
      :output => "#{event.output}",  
      :event_name => "#{event.name}",
      :patch_publication_date => "#{event.patch_publication_date}",
      :plugin_version => "#{event.plugin_version}",
      :event_port => "#{event.port.number}",
      :risk => "#{event.risk}",
      :see_also => "#{event.see_also}",
      :severity => "#{event.severity.in_words}",
      :solution => "#{event.solution}",
      :synopsis => "#{event.synopsis}",
      :xref => "#{event.xref}",
      :bool_crit => "#{event.critical?}",
      :bool_high => "#{event.high?}", 
      :bool_med => "#{event.medium?}",
      :bool_low => "#{event.low?}",
      :bool_info => "#{event.informational?}")
end # end event.informational?

0 个答案:

没有答案