demoman 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Mitch Dempsey
1
+ Copyright (c) 2010 Mitch Dempsey
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.textile ADDED
@@ -0,0 +1,60 @@
1
+ h1. demoman
2
+
3
+ Demoman allows you to extract metadata from Half-Life and Half-Life 2 demo (.dem) files.
4
+
5
+ h2. Installation
6
+
7
+ <pre>
8
+ sudo gem install demoman
9
+ </pre>
10
+
11
+ And add the gem to your environment.rb configuration as a gem dependency:
12
+
13
+ <pre>
14
+ config.gem 'demoman'
15
+ </pre>
16
+
17
+
18
+ h2. Usage
19
+
20
+ <pre>
21
+ demo_object = Demoman.new("test/test.dem")
22
+
23
+ # Server IP Address
24
+ puts demo_object.server_address
25
+
26
+
27
+ # Player who recorded the demo
28
+ puts demo_object.player_name
29
+
30
+ # The map being played
31
+ puts demo_object.map
32
+
33
+ # The game directory (dod, tf2, ...)
34
+ puts demo_object.game_dir
35
+
36
+ # The duration of the demo (in seconds)
37
+ puts demo_object.duration
38
+
39
+ # The number of ticks in the demo
40
+ puts demo_object.ticks
41
+
42
+ # The total number of frames
43
+ puts demo_object.frames
44
+
45
+ </pre>
46
+
47
+
48
+ h2. Note on Patches/Pull Requests
49
+
50
+ * Fork the project.
51
+ * Make your feature addition or bug fix.
52
+ * Add tests for it. This is important so I don't break it in a
53
+ future version unintentionally.
54
+ * Commit, do not mess with rakefile, version, or history.
55
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
56
+ * Send me a pull request. Bonus points for topic branches.
57
+
58
+ h2. Copyright
59
+
60
+ Copyright (c) 2010 Mitch Dempsey. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/demoman.gemspec CHANGED
@@ -5,22 +5,22 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{demoman}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mitch Dempsey"]
12
- s.date = %q{2010-09-09}
12
+ s.date = %q{2010-09-11}
13
13
  s.description = %q{Library for reading metadata from Half-Life demo files}
14
14
  s.email = %q{mrdempsey@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "LICENSE",
23
- "README.rdoc",
23
+ "README.textile",
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "demoman.gemspec",
data/lib/demoman.rb CHANGED
@@ -3,12 +3,31 @@ class Demoman
3
3
 
4
4
  attr_reader :server_address, :player_name, :map, :game_dir, :demo_protocol, :network_protocol, :type, :duration, :ticks, :frames, :sign_on_length
5
5
 
6
- def initialize(file)
7
- io = File.new(file, "r")
6
+ def initialize(file=nil)
8
7
 
9
- data = io.sysread(4096)
8
+ unless file.nil?
9
+ io = File.new(file, "r")
10
+ data = io.sysread(4096)
11
+ parse_data data
12
+ end
10
13
 
14
+ end
15
+
16
+ def self.from_file(file)
17
+ io = File.new(file, "r")
18
+ data = io.sysread(4096)
11
19
 
20
+ Demoman.from_string(data)
21
+ end
22
+
23
+ def self.from_string(data)
24
+ demoman = Demoman.new
25
+ demoman.parse_data(data)
26
+ demoman
27
+ end
28
+
29
+
30
+ def parse_data(data)
12
31
  demodata = data.unpack("A8/I/I/A260/A260/A260/A260/f/I/I/I/")
13
32
  @type = demodata[0]
14
33
  @demo_protocol = demodata[1]
@@ -22,8 +41,8 @@ class Demoman
22
41
  @ticks = demodata[8]
23
42
  @frames = demodata[9]
24
43
  @sign_on_length = demodata[10]
25
-
26
-
44
+ nil
27
45
  end
28
46
 
47
+
29
48
  end
data/test/test_demoman.rb CHANGED
@@ -18,4 +18,40 @@ class TestDemoman < Test::Unit::TestCase
18
18
  #["HL2DEMO", 3, 7, "69.90.189.79:27037", "Ham Salad[AOF]", "dod_jagd", "dod", 13.2424249649048, 874, 390, 115449]
19
19
 
20
20
  end
21
+
22
+ should "new style load demo" do
23
+
24
+ demoman = Demoman.from_file("test/test.dem")
25
+
26
+ assert_equal "69.90.189.79:27037", demoman.server_address
27
+ assert_equal "Ham Salad[AOF]", demoman.player_name
28
+ assert_equal "dod_jagd", demoman.map
29
+ assert_equal "dod", demoman.game_dir
30
+ assert_equal 3, demoman.demo_protocol
31
+ assert_equal 7, demoman.network_protocol
32
+
33
+ assert_equal 874, demoman.ticks
34
+ assert_equal 390, demoman.frames
35
+ assert_equal 115449, demoman.sign_on_length
36
+ end
37
+
38
+ should "read from string" do
39
+ io = File.new("test/test.dem", "r")
40
+ data = io.sysread(4096)
41
+
42
+ demoman = Demoman.from_string(data)
43
+
44
+ assert_equal "69.90.189.79:27037", demoman.server_address
45
+ assert_equal "Ham Salad[AOF]", demoman.player_name
46
+ assert_equal "dod_jagd", demoman.map
47
+ assert_equal "dod", demoman.game_dir
48
+ assert_equal 3, demoman.demo_protocol
49
+ assert_equal 7, demoman.network_protocol
50
+
51
+ assert_equal 874, demoman.ticks
52
+ assert_equal 390, demoman.frames
53
+ assert_equal 115449, demoman.sign_on_length
54
+
55
+ end
56
+
21
57
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demoman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mitch Dempsey
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-09 00:00:00 -07:00
18
+ date: 2010-09-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -40,12 +40,12 @@ extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
42
  - LICENSE
43
- - README.rdoc
43
+ - README.textile
44
44
  files:
45
45
  - .document
46
46
  - .gitignore
47
47
  - LICENSE
48
- - README.rdoc
48
+ - README.textile
49
49
  - Rakefile
50
50
  - VERSION
51
51
  - demoman.gemspec
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = demoman
2
-
3
- Demoman allows you to extract metadata from Half-Life and Half-Life 2 demo (.dem) files.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Mitch Dempsey. See LICENSE for details.