Class: Viiite::Tms

Inherits:
Struct
  • Object
show all
Defined in:
lib/viiite/tms.rb

Constant Summary

FORMAT =
"%10.6u %10.6y %10.6t %10.6r"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(utime, stime, cutime, cstime, real) ⇒ Tms

Returns a new instance of Tms



6
7
8
# File 'lib/viiite/tms.rb', line 6

def initialize(utime, stime, cutime, cstime, real)
  super # ensure we have all 5 non-nil arguments
end

Instance Attribute Details

#cstimeObject

Returns the value of attribute cstime

Returns:

  • (Object)

    the current value of cstime



2
3
4
# File 'lib/viiite/tms.rb', line 2

def cstime
  @cstime
end

#cutimeObject

Returns the value of attribute cutime

Returns:

  • (Object)

    the current value of cutime



2
3
4
# File 'lib/viiite/tms.rb', line 2

def cutime
  @cutime
end

#realObject

Returns the value of attribute real

Returns:

  • (Object)

    the current value of real



2
3
4
# File 'lib/viiite/tms.rb', line 2

def real
  @real
end

#stimeObject Also known as: system

Returns the value of attribute stime

Returns:

  • (Object)

    the current value of stime



2
3
4
# File 'lib/viiite/tms.rb', line 2

def stime
  @stime
end

#utimeObject Also known as: user

Returns the value of attribute utime

Returns:

  • (Object)

    the current value of utime



2
3
4
# File 'lib/viiite/tms.rb', line 2

def utime
  @utime
end

Class Method Details

.coerce(arg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/viiite/tms.rb', line 10

def self.coerce(arg)
  case arg
  when Viiite::Tms
    arg
  when Numeric
    Viiite::Tms.new arg, 0.0, 0.0, 0.0, 0.0
  when Hash
    Viiite::Tms.new(*members.collect{|f| arg[f] || 0.0})
  when Array
    Viiite::Tms.new(*arg)
  else
    raise ArgumentError, "Invalid value #{arg.inspect} for Viiite::Tms"
  end
end

.membersObject



75
# File 'lib/viiite/tms.rb', line 75

def self.members; super.map(&:to_sym); end

Instance Method Details

#*(other) ⇒ Object



38
# File 'lib/viiite/tms.rb', line 38

def *(other); memberwise(:*, other) end

#+(other) ⇒ Object



36
# File 'lib/viiite/tms.rb', line 36

def +(other); memberwise(:+, other) end

#-(other) ⇒ Object



37
# File 'lib/viiite/tms.rb', line 37

def -(other); memberwise(:-, other) end

#/(other) ⇒ Object



39
# File 'lib/viiite/tms.rb', line 39

def /(other); memberwise(:/, other) end

#coerce(other) ⇒ Object



41
42
43
# File 'lib/viiite/tms.rb', line 41

def coerce(other)
  [self, other]
end

#format(format = nil, *args) ⇒ Object Also known as: to_s



49
50
51
52
53
54
55
56
57
58
# File 'lib/viiite/tms.rb', line 49

def format(format = nil, *args)
  str = (format || FORMAT).dup
  str.gsub!(/(%[-+.\d]*)u/) { "#{$1}f" % utime }
  str.gsub!(/(%[-+.\d]*)y/) { "#{$1}f" % stime }
  str.gsub!(/(%[-+.\d]*)U/) { "#{$1}f" % cutime }
  str.gsub!(/(%[-+.\d]*)Y/) { "#{$1}f" % cstime }
  str.gsub!(/(%[-+.\d]*)t/) { "#{$1}f" % total }
  str.gsub!(/(%[-+.\d]*)r/) { "(#{$1}f)" % real }
  format ? str % args : str
end

#membersObject



74
# File 'lib/viiite/tms.rb', line 74

def members; super.map(&:to_sym); end

#to_hObject



45
46
47
# File 'lib/viiite/tms.rb', line 45

def to_h
  @to_h ||= Hash[members.zip(values)]
end

#to_ruby_literalObject



32
33
34
# File 'lib/viiite/tms.rb', line 32

def to_ruby_literal
  "Viiite::Tms(#{to_a.collect{|f| f.inspect}.join(',')})"
end

#totalObject



28
29
30
# File 'lib/viiite/tms.rb', line 28

def total
  cutime + cstime + stime + utime
end