tf2_line_parser 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +43 -0
  6. data/README.md +15 -0
  7. data/lib/tf2_line_parser/events/assist.rb +13 -0
  8. data/lib/tf2_line_parser/events/capture_block.rb +26 -0
  9. data/lib/tf2_line_parser/events/charge_deployed.rb +23 -0
  10. data/lib/tf2_line_parser/events/chat.rb +38 -0
  11. data/lib/tf2_line_parser/events/console_say.rb +24 -0
  12. data/lib/tf2_line_parser/events/current_score.rb +13 -0
  13. data/lib/tf2_line_parser/events/damage.rb +24 -0
  14. data/lib/tf2_line_parser/events/domination.rb +12 -0
  15. data/lib/tf2_line_parser/events/event.rb +70 -0
  16. data/lib/tf2_line_parser/events/final_score.rb +13 -0
  17. data/lib/tf2_line_parser/events/heal.rb +25 -0
  18. data/lib/tf2_line_parser/events/kill.rb +13 -0
  19. data/lib/tf2_line_parser/events/match_end.rb +24 -0
  20. data/lib/tf2_line_parser/events/medic_death.rb +12 -0
  21. data/lib/tf2_line_parser/events/pickup_item.rb +28 -0
  22. data/lib/tf2_line_parser/events/point_capture.rb +26 -0
  23. data/lib/tf2_line_parser/events/revenge.rb +12 -0
  24. data/lib/tf2_line_parser/events/role_change.rb +28 -0
  25. data/lib/tf2_line_parser/events/round_length.rb +24 -0
  26. data/lib/tf2_line_parser/events/round_stalemate.rb +23 -0
  27. data/lib/tf2_line_parser/events/round_start.rb +23 -0
  28. data/lib/tf2_line_parser/events/round_win.rb +23 -0
  29. data/lib/tf2_line_parser/events/score.rb +29 -0
  30. data/lib/tf2_line_parser/events/suicide.rb +28 -0
  31. data/lib/tf2_line_parser/events/unknown.rb +28 -0
  32. data/lib/tf2_line_parser/line.rb +25 -0
  33. data/lib/tf2_line_parser/parser.rb +15 -0
  34. data/lib/tf2_line_parser/player.rb +19 -0
  35. data/lib/tf2_line_parser/version.rb +3 -0
  36. data/lib/tf2_line_parser.rb +13 -0
  37. data/script/bundler +10 -0
  38. data/script/ci +22 -0
  39. data/spec/fixtures/logs/broder_vs_epsilon.log +4539 -0
  40. data/spec/fixtures/logs/example.log +4528 -0
  41. data/spec/fixtures/logs/special_characters.log +275 -0
  42. data/spec/lib/tf2_line_parser/parser_spec.rb +273 -0
  43. data/spec/lib/tf2_line_parser/player_spec.rb +15 -0
  44. data/spec/spec_helper.rb +2 -0
  45. data/tf2_line_parser.gemspec +20 -0
  46. metadata +144 -0
@@ -0,0 +1,28 @@
1
+ module TF2LineParser
2
+ module Events
3
+
4
+ class Suicide < Event
5
+
6
+ def self.regex
7
+ @regex ||= /#{regex_time} #{regex_player} committed suicide with #{regex_suicide}/
8
+ end
9
+
10
+ def self.regex_suicide
11
+ @regex_role ||= '\"(?\'method\'\w*)\"'
12
+ end
13
+
14
+ def self.attributes
15
+ @attributes ||= [:time, :player_nick, :player_steamid, :player_team, :method]
16
+ end
17
+
18
+ attr_accessor :time, :player, :method
19
+
20
+ def initialize(time, player_name, player_steam_id, player_team, method)
21
+ @time = parse_time(time)
22
+ @player = Player.new(player_name, player_steam_id, player_team)
23
+ @method = method
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module TF2LineParser
2
+ module Events
3
+
4
+ class Unknown < Event
5
+
6
+ def self.regex
7
+ @regex ||= /#{regex_time} #{regex_unknown}/
8
+ end
9
+
10
+ def self.regex_unknown
11
+ "(?'unknown'.*)"
12
+ end
13
+
14
+ def self.attributes
15
+ @attributes ||= [:time, :unknown]
16
+ end
17
+
18
+ attr_accessor :time, :unknown
19
+
20
+ def initialize(time, unknown)
21
+ @time = parse_time(time)
22
+ @unknown = unknown
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require 'time'
2
+
3
+ module TF2LineParser
4
+
5
+ class Line
6
+
7
+ attr_accessor :line
8
+
9
+ def initialize(line)
10
+ @line = line.force_encoding('UTF-8').encode('UTF-16LE', :invalid => :replace, :replace => '').encode('UTF-8')
11
+ end
12
+
13
+ def parse
14
+ Events::Event.types.each do |type|
15
+ if match = line.match(type.regex)
16
+ @match ||= type.new(*type.regex_results(match))
17
+ break
18
+ end
19
+ end
20
+ @match
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ module TF2LineParser
2
+ class Parser
3
+
4
+ attr_accessor :line
5
+
6
+ def initialize(line)
7
+ @line = Line.new(line.to_s)
8
+ end
9
+
10
+ def parse
11
+ line.parse
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module TF2LineParser
2
+
3
+ class Player
4
+
5
+ attr_accessor :name, :steam_id, :team
6
+
7
+ def initialize(name, steam_id, team)
8
+ @name = name
9
+ @steam_id = steam_id
10
+ @team = team
11
+ end
12
+
13
+ def ==(other)
14
+ steam_id == other.steam_id
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,3 @@
1
+ module TF2LogLineParser
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,13 @@
1
+ require "tf2_line_parser/version"
2
+ require "tf2_line_parser/parser"
3
+ require "tf2_line_parser/player"
4
+
5
+ require "tf2_line_parser/events/event"
6
+ require "tf2_line_parser/events/score"
7
+ Dir[File.dirname(__FILE__) + '/tf2_line_parser/events/*.rb'].each {|file| require file }
8
+ require "tf2_line_parser/line"
9
+
10
+
11
+
12
+ module TF2LineParser
13
+ end
data/script/bundler ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "--- Making sure bundler is installed"
5
+
6
+ gem which bundler &> /dev/null || gem install bundler --no-ri --no-rdoc
7
+
8
+ echo "--- Installing gems"
9
+
10
+ bundle check --no-color || time bundle install --no-color
data/script/ci ADDED
@@ -0,0 +1,22 @@
1
+ run() {
2
+ time bundle exec $*
3
+ }
4
+
5
+ echo "--- Starting continuous integration build"
6
+
7
+ ./script/bundler
8
+
9
+ if [[ -d coverage ]]; then
10
+ echo "Removing old coverage report"
11
+ rm -r coverage
12
+ fi
13
+
14
+ echo "--- Running RSpec"
15
+
16
+ run rspec --color spec --format SpecCoverage --format progress --format html --out rspec.html
17
+ rspec=$?
18
+
19
+ if [[ $rspec -ne 0 ]]; then
20
+ echo "--- Some tests have failed."
21
+ exit 1
22
+ fi