Module: RMuh::RPT::Log::Util::UnitedOperations

Included in:
Parsers::UnitedOperationsLog, Parsers::UnitedOperationsLog, Parsers::UnitedOperationsRPT, Parsers::UnitedOperationsRPT
Defined in:
lib/rmuh/rpt/log/util/unitedoperations.rb

Overview

UnitedOperations module. This has a constant and some shared functions. This is shared amongst the two UO logs

Instance Method Summary collapse

Instance Method Details

#__check_match_arg(match) ⇒ Object



24
25
26
27
28
29
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 24

def __check_match_arg(match)
  fail(
    ArgumentError,
    'argument 1 must be of type MatchData'
  ) unless match.class == MatchData
end

#__guid_add_data(line, key) ⇒ Object



105
106
107
108
109
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 105

def __guid_add_data(line, key)
  data = ''
  data << line[key].to_s unless line[key].nil?
  data
end

#__guid_data_base(line) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 95

def __guid_data_base(line)
  if line[:iso8601].nil?
    return "#{line[:year]}#{line[:month]}#{line[:day]}" \
           "#{line[:hour]}#{line[:min]}#{line[:sec]}" \
           "#{line[:type]}"
  else
    return "#{line[:iso8601]}#{line[:type]}"
  end
end

#__line_modifiers(match, match_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 31

def __line_modifiers(match, match_name)
  m = match_name
  if [
    :year, :month, :day, :hour, :min, :sec, :player_num
  ].include?(m.to_sym)
    return match[m].to_i
  elsif [:server_time, :damage, :distance, :channel, :nearby_players]
    .include?(m.to_sym)
    return __modifiers(match, m)
  else
    return match[m]
  end
end

#__modifiers(match, match_name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 45

def __modifiers(match, match_name)
  m = match_name
  if [:server_time, :damage, :distance].include?(m.to_sym)
    return match[m].to_f
  elsif m.to_sym == :channel
    return match[m].downcase
  elsif m.to_sym == :nearby_players
    return __parse_nearby_players(match, m)
  end
end

#__parse_nearby_players(match, match_name) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 56

def __parse_nearby_players(match, match_name)
  m = match_name
  if match[m] != 'None.'
    val = match[m].gsub('[', '').gsub(']', '').gsub('"', '')
    return val.split(',')
  else
    return []
  end
end

#add_guid!(line) ⇒ Object



81
82
83
84
85
86
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 81

def add_guid!(line)
  data = __guid_data_base(line)
  s = guid_keys.map { |k| __guid_add_data(line, k) }
  line[:event_guid] = Digest::SHA1.hexdigest data + s.join('')
  line
end

#guid_keysObject



88
89
90
91
92
93
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 88

def guid_keys
  [
    :message, :victim, :offender, :server_time, :damage,
    :distance, :player, :player_beguid, :channel
  ]
end

#m_to_h(match) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 15

def m_to_h(match)
  __check_match_arg(match)
  h = {}
  match.names.each do |m|
    h.merge!(m.to_sym => __line_modifiers(match, m))
  end
  h
end

#validate_bool_opt(opts, key) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 111

def validate_bool_opt(opts, key)
  fail(
    ArgumentError,
    "#{key} must be a boolean value (true|false)"
  ) if opts.key?(key) && \
       ![TrueClass, FalseClass].include?(opts[key].class)
end

#validate_timezone(opts) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 119

def validate_timezone(opts)
  fail(
    ArgumentError,
    ':tiemzone must be an instance of TZInfo::DataTimezone'
  ) if opts.key?(:timezone) &&
       opts[:timezone].class != TZInfo::DataTimezone
end

#zulu!(line, timezone) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 66

def zulu!(line, timezone)
  t = timezone.local_to_utc(Time.new(line[:year], line[:month],
                                     line[:day], line[:hour],
                                     line[:min], line[:sec]))

  [:year, :month, :day, :hour, :min, :sec].each do |k|
    line[k] = t.send(k)
  end

  line[:iso8601] = t.strftime('%Y-%m-%dT%H:%M:%SZ')
  line[:dtg] = t.strftime('%d%H%MZ %^b %y')

  line
end