class Embulk::Guess::RegexApacheLogGuesser

Attributes

columns[R]
patterns[R]

Public Class Methods

new(patterns=nil, columns=nil) click to toggle source
# File lib/embulk/guess/regex.rb, line 54
def initialize(patterns=nil, columns=nil)
  @patterns = (patterns || [])
  @columns = (columns || [])
end

Public Instance Methods

+(guesser) click to toggle source
# File lib/embulk/guess/regex.rb, line 59
def +(guesser)
  RegexApacheLogGuesser.new(@patterns + guesser.patterns, @columns + guesser.columns)
end
compile() click to toggle source
# File lib/embulk/guess/regex.rb, line 76
def compile
  Regexp.compile pattern_str
end
guessed() click to toggle source
# File lib/embulk/guess/regex.rb, line 68
def guessed
    ret = {}
    ret["type"] = "regex"
    ret["regex"] = pattern_str
    ret["columns"] = columns
    ret
end
integer(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 114
def integer(name, opts={})
  @patterns << "(?<#{opts[:regex_name] || name}>[0-9]+)"
  @columns << {:name => name, :type => 'long'}.merge(opts)
  self
end
integer_or_minus(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 120
def integer_or_minus(name, opts={})
  @patterns << "(?<#{opts[:regex_name] || name}>[0-9]+|-)"
  @columns << {:name => name, :type => 'long'}.merge(opts)
  self
end
ip(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 84
def ip(name, opts={})
  @patterns << "(?<#{opts[:regex_name] || name}>[.:0-9]+)"
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end
ip_or_minus(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 90
def ip_or_minus(name, opts={})
  @patterns << "(?<#{opts[:regex_name] || name}>[.:0-9]+|-)"
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end
kakko(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 126
def kakko(name, opts={})
  @patterns << "\\[(?<#{opts[:regex_name] || name}>[^\\]]*)\\]"
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end
match_all?(lines) click to toggle source
# File lib/embulk/guess/regex.rb, line 63
def match_all?(lines)
  ptn = compile
  lines.all? {|line| ptn.match(line)}
end
method_path_protocol() click to toggle source
# File lib/embulk/guess/regex.rb, line 132
def method_path_protocol
  @patterns << '"((?<method>\S+) (?<path>\S+) (?<protocol>HTTP/\d+\.\d+)|-)"'
  @columns << {:name => 'method', :type => 'string'}
  @columns << {:name => 'path', :type => 'string'}
  @columns << {:name => 'protocol', :type => 'string'}
  self
end
pattern_str() click to toggle source
# File lib/embulk/guess/regex.rb, line 80
def pattern_str
  '^' + @patterns.join(' ') + '$'
end
string(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 102
def string(name, opts={})
  @patterns << "\"(?<#{opts[:regex_name] || name}>[^\"]*)\""
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end
string_or_minus(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 108
def string_or_minus(name, opts={})
  @patterns << "\"(?<#{opts[:regex_name] || name}>[^\"]*|-)\""
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end
token(name, opts={}) click to toggle source
# File lib/embulk/guess/regex.rb, line 96
def token(name, opts={})
  @patterns << "(?<#{opts[:regex_name] || name}>\\S+)"
  @columns << {:name => name, :type => 'string'}.merge(opts)
  self
end