Class: Viiite::Tms
- Inherits:
-
Struct
- Object
- Struct
- Viiite::Tms
- Defined in:
- lib/viiite/tms.rb
Constant Summary collapse
- FMTSTR =
"%10.6u %10.6y %10.6t %10.6r"
Instance Attribute Summary collapse
-
#cstime ⇒ Object
Returns the value of attribute cstime.
-
#cutime ⇒ Object
Returns the value of attribute cutime.
-
#real ⇒ Object
Returns the value of attribute real.
-
#stime ⇒ Object
Returns the value of attribute stime.
-
#utime ⇒ Object
Returns the value of attribute utime.
Class Method Summary collapse
Instance Method Summary collapse
- #*(x) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #coerce(other) ⇒ Object
- #format(arg0 = nil, *args) ⇒ Object (also: #to_s)
-
#initialize(utime, stime, cutime, cstime, real) ⇒ Tms
constructor
A new instance of Tms.
- #members ⇒ Object
- #to_h ⇒ Object
- #to_ruby_literal ⇒ Object
- #total ⇒ Object
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
#cstime ⇒ Object
Returns the value of attribute cstime
2 3 4 |
# File 'lib/viiite/tms.rb', line 2 def cstime @cstime end |
#cutime ⇒ Object
Returns the value of attribute cutime
2 3 4 |
# File 'lib/viiite/tms.rb', line 2 def cutime @cutime end |
#real ⇒ Object
Returns the value of attribute real
2 3 4 |
# File 'lib/viiite/tms.rb', line 2 def real @real end |
#stime ⇒ Object
Returns the value of attribute stime
2 3 4 |
# File 'lib/viiite/tms.rb', line 2 def stime @stime end |
#utime ⇒ Object
Returns the value of attribute 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 |
.members ⇒ Object
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 |
#members ⇒ Object
71 |
# File 'lib/viiite/tms.rb', line 71 def members; super.map(&:to_sym); end |
#to_h ⇒ Object
42 43 44 |
# File 'lib/viiite/tms.rb', line 42 def to_h @to_h ||= Hash[members.zip(values)] end |
#to_ruby_literal ⇒ Object
29 30 31 |
# File 'lib/viiite/tms.rb', line 29 def to_ruby_literal "Viiite::Tms(#{to_a.collect{|f| f.inspect}.join(',')})" end |
#total ⇒ Object
25 26 27 |
# File 'lib/viiite/tms.rb', line 25 def total cutime + cstime + stime + utime end |