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
TODO: Module documentation
Instance Method Summary collapse
- #__check_match_arg(match) ⇒ Object
- #__guid_add_data(line, key) ⇒ Object
- #__guid_data_base(line) ⇒ Object
- #__line_modifiers(match, match_name) ⇒ Object
- #__modifiers(match, match_name) ⇒ Object
- #__parse_nearby_players(match, match_name) ⇒ Object
- #add_guid!(line) ⇒ Object
- #guid_keys ⇒ Object
- #m_to_h(match) ⇒ Object
- #validate_bool_opt(opts, key) ⇒ Object
- #validate_timezone(opts) ⇒ Object
- #zulu!(line, timezone) ⇒ Object
Instance Method Details
#__check_match_arg(match) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 23 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
102 103 104 105 106 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 102 def __guid_add_data(line, key) data = '' data << line[key].to_s unless line[key].nil? data end |
#__guid_data_base(line) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 92 def __guid_data_base(line) if line[:iso8601].nil? return "#{line[:year]}#{line[:month]}#{line[:day]}" \ "#{line[:hour]}#{line[:min]}#{line[:sec]}" \ "#{line[:type].to_s}" else return "#{line[:iso8601]}#{line[:type].to_s}" end end |
#__line_modifiers(match, match_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 30 def __line_modifiers(match, match_name) m = match_name if [:year, :month, :day, :hour, :min, :sec].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
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 42 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
53 54 55 56 57 58 59 60 61 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 53 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
78 79 80 81 82 83 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 78 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_keys ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 85 def guid_keys [ :message, :victim, :offender, :server_time, :damage, :distance, :player, :player_beguid, :channel ] end |
#m_to_h(match) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 14 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
108 109 110 111 112 113 114 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 108 def validate_bool_opt(opts, key) if opts.key?(key) && ![TrueClass, FalseClass].include?(opts[key].class) fail ArgumentError, "#{key} must be a boolean value (true|false)" end end |
#validate_timezone(opts) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 116 def validate_timezone(opts) if opts.key?(:timezone) && opts[:timezone].class != TZInfo::DataTimezone fail ArgumentError, ':tiemzone must be an instance of TZInfo::DataTimezone' end end |
#zulu!(line, timezone) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rmuh/rpt/log/util/unitedoperations.rb', line 63 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 |