Class: CEF::Parser
- Inherits:
-
Object
- Object
- CEF::Parser
- Defined in:
- lib/cef/parser.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
TODO: deal with escaping delimeters.
Instance Method Summary collapse
-
#initialize(*args) {|_self| ... } ⇒ Parser
constructor
A new instance of Parser.
- #parse_file ⇒ Object
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Parser
Returns a new instance of Parser.
9 10 11 12 13 14 |
# File 'lib/cef/parser.rb', line 9 def initialize(*args) # Parser.new(:foo=>"bar) Hash[*args].each { |argname, argval| self.send(("%s="%argname), argval) } yield self if block_given? end |
Instance Attribute Details
#file_name ⇒ Object
TODO: deal with escaping delimeters
7 8 9 |
# File 'lib/cef/parser.rb', line 7 def file_name @file_name end |
Instance Method Details
#parse_file ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cef/parser.rb', line 16 def parse_file events=[] File.open(file_name) do |f| f.each_line do |line| line.chomp! prefix=line.split(/\|/) e=Event.new extension_string=prefix[7..-1].join("|") extension_av_pairs=extension_string.split(/ ([\w\.]+)=/) extension_av_pairs.shift begin extension=Hash[ *extension_av_pairs.map {|i| i.strip} ] extension.each do |k,v| next if k.match(/^ad\./) methname=CEF::ATTRIBUTES.invert[k].to_s #puts "METHNAME: #{k} -> #{methname}" e.send("%s=" % methname, v) end rescue Exception => except puts except. pp extension_av_pairs puts line next end %w{ deviceVendor deviceProduct deviceVersion deviceEventClassId name deviceSeverity }.each_with_index {|att,i| e.send("%s="%att,prefix[i+1]) } if block_given? yield e else events.push e end end end events end |