Class: Schatz::Input::TextExport

Inherits:
Export
  • Object
show all
Includes:
ParserHelper
Defined in:
lib/schatz/input/text_export.rb

Constant Summary

Constants included from ParserHelper

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

Methods included from ParserHelper

#parse_ports_field, #push_connection

Constructor Details

#initialize(options) ⇒ TextExport

Returns a new instance of TextExport.



7
8
9
10
11
12
13
14
# File 'lib/schatz/input/text_export.rb', line 7

def initialize(options)
  @options = options
  @addresses_with_ports = []
  @conversations 	= []
  @links_with_ports = []
  @file = File.open(@options[:file_name], 'r')
  check_format
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/schatz/input/text_export.rb', line 6

def file
  @file
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/schatz/input/text_export.rb', line 6

def options
  @options
end

Instance Method Details

#check_formatObject

Raises:

  • (IncorrectTextFormat)


30
31
32
# File 'lib/schatz/input/text_export.rb', line 30

def check_format
  raise IncorrectTextFormat, "format of txt file is incorrect" unless split_lines.all? { |line| line =~ REGEXP_HOST || line =~ LINK }
end

#get_conversationsObject



20
21
22
# File 'lib/schatz/input/text_export.rb', line 20

def get_conversations
  TxtLineParser.new(split_lines).connections
end


16
17
18
# File 'lib/schatz/input/text_export.rb', line 16

def get_links
  TxtLineParser.new(split_lines).links
end

#split_linesObject

split txt file into lines



25
26
27
28
# File 'lib/schatz/input/text_export.rb', line 25

def split_lines
  @file.pos=0
  @file.read.split(/\n/).map{ |line| line.gsub /\r/, "" }
end