-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.rb
48 lines (39 loc) · 1 KB
/
line.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# frozen_string_literal: true
require 'ipaddress'
module LogsParser
module Entries
class Line
def initialize(line, ip_validation_lib = IPAddress)
@path, @addr = line.split
@ip_validation_lib = ip_validation_lib
end
def call
to_h
end
private
attr_reader :path, :addr, :ip_validation_lib
def to_h
{
addr: addr,
path: path,
errors: validate
}
end
def validate
@validate ||= [].tap do |result|
path_addr_present? result
addr_valid? result
end
end
##
# Becouse example file do not contains any valid IP addr, validation is commented here
# IN ORDER TEST TO PASS WE SCHOULD UNCOMENT IT!!!
def addr_valid?(res)
res << "Provided IP addr isn't valid!" unless ip_validation_lib.valid? addr
end
def path_addr_present?(res)
res << "Line format isn't valid!" unless path && addr
end
end
end
end