Class: Schatz::Input::TextExport
- 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
-
#file ⇒ Object
Returns the value of attribute file.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #check_format ⇒ Object
- #get_conversations ⇒ Object
- #get_links ⇒ Object
-
#initialize(options) ⇒ TextExport
constructor
A new instance of TextExport.
-
#split_lines ⇒ Object
split txt file into lines.
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 = @addresses_with_ports = [] @conversations = [] @links_with_ports = [] @file = File.open(@options[:file_name], 'r') check_format end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/schatz/input/text_export.rb', line 6 def file @file end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/schatz/input/text_export.rb', line 6 def @options end |
Instance Method Details
#check_format ⇒ Object
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_conversations ⇒ Object
20 21 22 |
# File 'lib/schatz/input/text_export.rb', line 20 def get_conversations TxtLineParser.new(split_lines).connections end |
#get_links ⇒ Object
16 17 18 |
# File 'lib/schatz/input/text_export.rb', line 16 def get_links TxtLineParser.new(split_lines).links end |
#split_lines ⇒ Object
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 |