Class: Squiggle::LogLine

Inherits:
Object
  • Object
show all
Defined in:
lib/squiggle/log_line.rb

Constant Summary collapse

@@domain_parser =
DomainParser.new(File.dirname(__FILE__) +  "/../../lib/effective_tld_names.dat")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ LogLine

Returns a new instance of LogLine.

Yields:

  • (_self)

Yield Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/squiggle/log_line.rb', line 26

def initialize
  @errors = {}
  @invalid = false
  # Set defaults
  self.pageview = false
  self.cached = false
  yield self if block_given?
  class << @errors
    def to_s
      self.map { |(k,v)| "#{k} => #{v}" }.join(", ")
    end
  end
end

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes.



9
10
11
# File 'lib/squiggle/log_line.rb', line 9

def bytes
  @bytes
end

#cache_siblingObject

Returns the value of attribute cache_sibling.



11
12
13
# File 'lib/squiggle/log_line.rb', line 11

def cache_sibling
  @cache_sibling
end

#cache_statusObject

Returns the value of attribute cache_status.



10
11
12
# File 'lib/squiggle/log_line.rb', line 10

def cache_status
  @cache_status
end

#cachedObject Also known as: cached?

Returns the value of attribute cached.



12
13
14
# File 'lib/squiggle/log_line.rb', line 12

def cached
  @cached
end

#client_ipObject

Returns the value of attribute client_ip.



13
14
15
# File 'lib/squiggle/log_line.rb', line 13

def client_ip
  @client_ip
end

#created_atObject

Returns the value of attribute created_at.



14
15
16
# File 'lib/squiggle/log_line.rb', line 14

def created_at
  @created_at
end

#errorsObject (readonly)

Returns the value of attribute errors.



21
22
23
# File 'lib/squiggle/log_line.rb', line 21

def errors
  @errors
end

#http_resp_codeObject

Returns the value of attribute http_resp_code.



15
16
17
# File 'lib/squiggle/log_line.rb', line 15

def http_resp_code
  @http_resp_code
end

#mime_typeObject

Returns the value of attribute mime_type.



16
17
18
# File 'lib/squiggle/log_line.rb', line 16

def mime_type
  @mime_type
end

#original_lineObject

Returns the value of attribute original_line.



20
21
22
# File 'lib/squiggle/log_line.rb', line 20

def original_line
  @original_line
end

#pageviewObject Also known as: pageview?

Returns the value of attribute pageview.



17
18
19
# File 'lib/squiggle/log_line.rb', line 17

def pageview
  @pageview
end

#uriObject

Returns the value of attribute uri.



18
19
20
# File 'lib/squiggle/log_line.rb', line 18

def uri
  @uri
end

#usernameObject

Returns the value of attribute username.



19
20
21
# File 'lib/squiggle/log_line.rb', line 19

def username
  @username
end

Instance Method Details

#copy_lineObject



98
99
100
101
# File 'lib/squiggle/log_line.rb', line 98

def copy_line
  arr = [ bytes, cached, client_ip, created_at, uri.toplevel, uri.host, http_resp_code, mime_type, (pageview ? 1 : 0), uri.path, uri.scheme, username ]
  arr.map { |entry| "\"#{entry}\"" }.join(",")
end

#costObject

Returns the cost for this line as a float TODO: Make the logserver an event machine and use EM::Deferrable here??



93
94
95
96
# File 'lib/squiggle/log_line.rb', line 93

def cost
  pc = PolicyClient.new(self)
  pc.cost
end

#invalid?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/squiggle/log_line.rb', line 40

def invalid?
  # TODO: Run more checks and log if a check fails
  return true if @invalid
  if @uri.nil?
    @errors[:uri] = "Missing URL FROM #{@original_line}"
    return true
  end
  unless http_resp_code =~ /\A[+-]?\d+\Z/
    @errors[:http_resp_code] = "Invalid HTTP Response Code"
    return true
  end
  if http_resp_code && http_resp_code.to_i == 407
    @errors[:http_resp_code] = "407 code is ignored so setting to invalid"
    return true
  end
end

#valid?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/squiggle/log_line.rb', line 57

def valid?
  !invalid?
end