Class: Schatz::Input::TxtLineParser

Inherits:
Parser
  • Object
show all
Includes:
ParserHelper
Defined in:
lib/schatz/input/txt_line_parser.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

Attributes inherited from Parser

#connections, #links

Instance Method Summary collapse

Methods included from ParserHelper

#parse_ports_field, #push_connection

Constructor Details

#initialize(lines) ⇒ TxtLineParser

Returns a new instance of TxtLineParser.



5
6
7
# File 'lib/schatz/input/txt_line_parser.rb', line 5

def initialize(lines)
  super(lines)
end

Instance Method Details

#parse(line) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/schatz/input/txt_line_parser.rb', line 9

def parse(line)
  case line
  when REGEXP_HOST_PORTS
    parse_ports_field($2).map do |port| 
      @connections << Connection.new do |c|
        c.host = $1
        c.port = port
        c.scheme = "tcp"
      end
    end
  when LINK
    @links << Connection.new do |c|
      c.scheme = $1
      c.host   = $2
      c.port   = $3.to_i if $3           
    end
  end
end