Class: SpeedGun::Source::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/speed_gun/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, code, wall, cpu, calls, allocations) ⇒ Line

Returns a new instance of Line.



19
20
21
22
# File 'lib/speed_gun/source.rb', line 19

def initialize(line, code, wall, cpu, calls, allocations)
  @id = SecureRandom.uuid
  @line, @code, @wall, @cpu, @calls, @allocations = line, code, wall, cpu, calls, allocations
end

Instance Attribute Details

#allocationsObject (readonly)

Returns the value of attribute allocations.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def allocations
  @allocations
end

#callsObject (readonly)

Returns the value of attribute calls.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def calls
  @calls
end

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def code
  @code
end

#cpuObject (readonly)

Returns the value of attribute cpu.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def cpu
  @cpu
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def id
  @id
end

#lineObject (readonly)

Returns the value of attribute line.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def line
  @line
end

#wallObject (readonly)

Returns the value of attribute wall.



9
10
11
# File 'lib/speed_gun/source.rb', line 9

def wall
  @wall
end

Class Method Details

.from_hash(hash, id = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/speed_gun/source.rb', line 11

def self.from_hash(hash, id = nil)
  keys = %w(line code wall cpu calls allocations)
  vals = keys.map { |k| hash[k] }
  new(*vals).tap do |line|
    line.instance_variable_set(:@id, id) if id
  end
end

Instance Method Details

#to_hashObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/speed_gun/source.rb', line 28

def to_hash
  {
    line: line,
    code: code,
    wall: wall,
    cpu: cpu,
    calls: calls,
    allocations: allocations
  }
end

#to_sObject



24
25
26
# File 'lib/speed_gun/source.rb', line 24

def to_s
  format('% 8.1fms + % 8.1fms (% 5d) % 5d allocs | %04d %s', cpu / 1000.0, (wall - cpu) / 1000.0, calls, allocations, line, code)
end