Class: Demoman::DemoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/demoman/demo_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ DemoFile

Returns a new instance of DemoFile.



7
8
9
10
11
12
13
14
15
# File 'lib/demoman/demo_file.rb', line 7

def initialize(file=nil)
  
  unless file.nil?
    io = File.new(file, "r")
    data = io.sysread(4096)
    parse_data data
  end
  
end

Instance Attribute Details

#demo_protocolObject (readonly)

Returns the value of attribute demo_protocol.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def demo_protocol
  @demo_protocol
end

#durationObject (readonly)

Returns the value of attribute duration.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def duration
  @duration
end

#framesObject (readonly)

Returns the value of attribute frames.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def frames
  @frames
end

#game_dirObject (readonly)

Returns the value of attribute game_dir.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def game_dir
  @game_dir
end

#mapObject (readonly)

Returns the value of attribute map.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def map
  @map
end

#network_protocolObject (readonly)

Returns the value of attribute network_protocol.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def network_protocol
  @network_protocol
end

#player_nameObject (readonly)

Returns the value of attribute player_name.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def player_name
  @player_name
end

#server_addressObject (readonly)

Returns the value of attribute server_address.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def server_address
  @server_address
end

#sign_on_lengthObject (readonly)

Returns the value of attribute sign_on_length.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def sign_on_length
  @sign_on_length
end

#ticksObject (readonly)

Returns the value of attribute ticks.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def ticks
  @ticks
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/demoman/demo_file.rb', line 5

def type
  @type
end

Instance Method Details

#parse_data(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/demoman/demo_file.rb', line 17

def parse_data(data)
  demodata = data.unpack("A8/I/I/A260/A260/A260/A260/f/I/I/I/")
  @type = demodata[0]
  @demo_protocol = demodata[1]
  @network_protocol = demodata[2]
  @server_address = demodata[3]
  @player_name = demodata[4]
  @map = demodata[5]
  @game_dir = demodata[6]
  
  @duration = demodata[7]
  @ticks = demodata[8]
  @frames = demodata[9]
  @sign_on_length = demodata[10]
  nil
end