Class: Viiite::Tms

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

Constant Summary collapse

FMTSTR =
"%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

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

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



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

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

Instance Method Details

#*(x) ⇒ Object



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

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

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#/(other) ⇒ Object



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

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

#coerce(other) ⇒ Object



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

def coerce(other)
  [self, other]
end

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



46
47
48
49
50
51
52
53
54
55
# File 'lib/viiite/tms.rb', line 46

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

#membersObject



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

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

#to_hObject



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

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

#to_ruby_literalObject



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

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

#totalObject



25
26
27
# File 'lib/viiite/tms.rb', line 25

def total
  cutime + cstime + stime + utime
end