Class: Schatz::Input::IncrExport
Constant Summary
ParserHelper::CONVERSATION_HTML, ParserHelper::CONVERSATION_ROW, ParserHelper::GCM_NUMBER, ParserHelper::IP_ADDRESS, ParserHelper::LINK, ParserHelper::LINK_HTML, ParserHelper::ONE_HYPHEN, ParserHelper::ONE_OR_MORE_COMMA, ParserHelper::ONE_PORT, ParserHelper::PORTS_WITH_PROTOCOL, ParserHelper::REGEXP_HOST, ParserHelper::REGEXP_HOST_PORTS, ParserHelper::SOURCE_SUBNET
Instance Attribute Summary collapse
Instance Method Summary
collapse
#parse_ports_field, #push_connection
Constructor Details
#initialize(options) ⇒ IncrExport
Returns a new instance of IncrExport.
12
13
14
15
|
# File 'lib/schatz/input/incr_export.rb', line 12
def initialize(options)
@options = options
@file = Nokogiri::HTML(File.open(@options[:file_name], 'r'))
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
10
11
12
|
# File 'lib/schatz/input/incr_export.rb', line 10
def file
@file
end
|
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/schatz/input/incr_export.rb', line 10
def options
@options
end
|
Instance Method Details
#delete_mess(row) ⇒ Object
39
40
41
|
# File 'lib/schatz/input/incr_export.rb', line 39
def delete_mess(row)
row.text.gsub(/[\n\t]/, "").gsub(/\u00A0/, " ").gsub(/\r\r/, " ").gsub(/\r/, "")
end
|
#delete_source_subnets(row) ⇒ Object
71
72
73
74
|
# File 'lib/schatz/input/incr_export.rb', line 71
def delete_source_subnets(row)
row.match(SOURCE_SUBNET).to_a.each{|reg| row.gsub!(/#{reg}/, "")} while row =~ SOURCE_SUBNET
row
end
|
#find_conv_table ⇒ Object
50
51
52
53
54
55
|
# File 'lib/schatz/input/incr_export.rb', line 50
def find_conv_table
reg1 = Regexp.new 'Conversation Type'
reg2 = Regexp.new 'CR/GCM Number'
reg3 = Regexp.new 'Destination Host'
find_table([reg1, reg2, reg3])
end
|
#find_links_table ⇒ Object
57
58
59
60
61
62
|
# File 'lib/schatz/input/incr_export.rb', line 57
def find_links_table
reg1 = Regexp.new 'Intranet Site'
reg2 = Regexp.new 'Reason and Activity'
reg3 = Regexp.new 'CR/GCM Number'
find_table([reg1, reg2, reg3])
end
|
#find_table(regs) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/schatz/input/incr_export.rb', line 64
def find_table(regs)
tables = @file.xpath("/html/body/table")
conv_table = tables.select {|t| regs.all?{ |regexp| t.text =~ regexp} }
raise IncorrectIncrFormat if conv_table.size > 1
tables.index(conv_table.first)
end
|
#get_conversations ⇒ Object
34
35
36
37
|
# File 'lib/schatz/input/incr_export.rb', line 34
def (table_number)
rows = @file.xpath("//table[#{table_number+1}]//tr")
rows.map {|row| delete_mess(row) }
end
|
#get_table(options = {}) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/schatz/input/incr_export.rb', line 43
def get_table options={}
allowed_keys= ["table_id"]
raise ArgumentError if options.empty?
options.keys.each {|key| raise IncorrentParameters unless allowed_keys.include? key.to_s}
@file.xpath("/html/body/table")[options[:table_id].to_i]
end
|
#rows_in_conversation_table ⇒ Object
eliminate the first row(names of the fields)
26
27
28
|
# File 'lib/schatz/input/incr_export.rb', line 26
def rows_in_conversation_table
(find_conv_table).select {|row| row =~ CONVERSATION_ROW }
end
|
#rows_in_links_table ⇒ Object
30
31
32
|
# File 'lib/schatz/input/incr_export.rb', line 30
def rows_in_links_table
(find_links_table)
end
|
#scan_gcm_numbers(rows) ⇒ Object
76
77
78
|
# File 'lib/schatz/input/incr_export.rb', line 76
def scan_gcm_numbers(rows)
rows.map{ |row| row.scan(GCM_NUMBER).first }.compact.map(&:downcase)
end
|