Class: RequestLogAnalyzer::FileFormat::Rails3::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/request_log_analyzer/file_format/rails3.rb

Constant Summary

MONTHS =

Used to handle conversion of abbrev. month name to a digit

%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

Instance Attribute Summary

Attributes inherited from Request

#attributes, #file_format, #lines

Instance Method Summary collapse

Methods inherited from Request

#<<, #add_line_hash, #add_parsed_line, #completed?, create, #empty?, #every, #first, #first_lineno, #has_line_type?, #initialize, #last_lineno, #timestamp, #validate

Methods included from Request::Converters

#convert_decimal, #convert_duration, #convert_epoch, #convert_eval, #convert_float, #convert_int, #convert_integer, #convert_nillable_string, #convert_path, #convert_string, #convert_sym, #convert_symbol, #convert_traffic, #convert_value, #sanitize_parameters

Constructor Details

This class inherits a constructor from RequestLogAnalyzer::Request

Instance Method Details

#convert_timestamp(value, definition) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/request_log_analyzer/file_format/rails3.rb', line 114

def convert_timestamp(value, definition)
  # the time value can be in 2 formats:
  # - 2010-10-26 02:27:15 +0000 (ruby 1.9.2)
  # - Thu Oct 25 16:15:18 -0800 2010
  if value =~ /^#{CommonRegularExpressions::TIMESTAMP_PARTS['Y']}/
    value.gsub!(/\W/,'')
    value[0..13].to_i
  else
    value.gsub!(/\W/,'')
    time_as_str = value[-4..-1] # year
    # convert the month to a 2-digit representation
    month = MONTHS.index(value[3..5])+1
    month < 10 ? time_as_str << "0#{month}" : time_as_str << month.to_s

    time_as_str << value[6..13] # day of month + time
    time_as_str.to_i
  end

end