Class: RMuh::RPT::Log::Parsers::UnitedOperationsLog

Inherits:
Base
  • Object
show all
Extended by:
Util::UnitedOperations, Util::UnitedOperationsLog
Includes:
Util::UnitedOperations, Util::UnitedOperationsLog
Defined in:
lib/rmuh/rpt/log/parsers/unitedoperationslog.rb

Overview

This is the UnitedOperations Log parser class. It separates the log in to an array of Hashes, one for each log line.

This can be used to rebuild the log file, from metadata alone.

It extends RMuh::RPT::Log::Parsers::Base

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::UnitedOperations

__check_match_arg, __guid_add_data, __guid_data_base, __line_modifiers, __modifiers, __parse_nearby_players, add_guid!, guid_keys, m_to_h, validate_bool_opt, validate_timezone, zulu!

Constructor Details

#initialize(opts = {}) ⇒ UnitedOperationsLog

This builds the object. There are three optional args for the Hash:

  • :chat – should chat lines be included?

  • :to_zulu – convert timestamp to zulu

  • :timezone – specify the server timezone

– TODO: Make this use an auto hash to instance variable function ++



47
48
49
50
51
52
# File 'lib/rmuh/rpt/log/parsers/unitedoperationslog.rb', line 47

def initialize(opts = {})
  self.class.validate_opts(opts)
  @include_chat = opts[:chat].nil? ? false : opts[:chat]
  @to_zulu = opts[:to_zulu].nil? ? true : opts[:to_zulu]
  @timezone = opts[:timezone].nil? ? UO_TZ : opts[:timezone]
end

Class Method Details

.validate_opts(opts) ⇒ Object

Validate the options that are passed in as arg 1 to the new() function

This raises ArgumentError if something doesn’t pass



31
32
33
34
35
36
37
38
# File 'lib/rmuh/rpt/log/parsers/unitedoperationslog.rb', line 31

def self.validate_opts(opts)
  fail(
    ArgumentError, 'arg 1 should be an instance of Hash'
  ) unless opts.is_a?(Hash)
  validate_bool_opt(opts, :to_zulu)
  validate_timezone(opts)
  validate_bool_opt(opts, :chat)
end

Instance Method Details

#parse(loglines) ⇒ Object



54
55
56
57
58
59
# File 'lib/rmuh/rpt/log/parsers/unitedoperationslog.rb', line 54

def parse(loglines)
  unless loglines.is_a?(StringIO)
    fail ArgumentError, 'arg 1 must be a StringIO object'
  end
  regex_matches(loglines)
end