Module: RCL

Defined in:
lib/rcl.rb,
lib/rcl/url.rb,
lib/rcl/xml.rb,
lib/rcl/base.rb,
lib/rcl/http.rb,
lib/rcl/smtp.rb,
lib/rcl/perms.rb,
lib/rcl/shell.rb,
lib/rcl/token.rb,
lib/rcl/timestamp.rb

Overview

timestamp.rb [email protected]

Defined Under Namespace

Modules: HTTP, Perms, SMTP, URL, XML Classes: Base, Shell, Timestamp, Token

Constant Summary collapse

NAME =
'rcl'
VERSION =
'0.0.5'
'Copyright (c) 2008 Ramsey Dow'

Class Method Summary collapse

Class Method Details



10
# File 'lib/rcl.rb', line 10

def self.copyright() RCL::COPYRIGHT end

.datestamp(ts) ⇒ Object

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rcl/timestamp.rb', line 91

def self.datestamp(ts)
  raise ArgumentError, 'nil ts' if ts.nil?
  raise ArgumentError, 'invalid ts class' if ts.class != Time

  str = []

  str << ts.year
  str << '0' if ts.month < 10
  str << ts.month
  str << '0' if ts.day < 10
  str << ts.day

  str.join
end

.datetimestamp(ts) ⇒ Object



122
123
124
# File 'lib/rcl/timestamp.rb', line 122

def self.datetimestamp(ts)
  "#{datestamp(ts)}T#{timestamp(ts)}"
end

.libdirObject



12
# File 'lib/rcl.rb', line 12

def self.libdir() File.expand_path(__FILE__).gsub(%r/\.rb$/, '') end

.ms_to_s(ms) ⇒ Object

convert milliseconds to hours, minutes, and seconds

Raises:

  • (ArgumentError)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rcl/timestamp.rb', line 73

def self.ms_to_s(ms)
  raise ArgumentError, 'nil ms' if ms.nil?
  raise ArgumentError, 'invalid ms class' if !ms.is_a?(Integer)

  s = ms % 60
  m = (ms / 60) % 60
  h = (ms / 3600) % 24

  str = []

  str << h.to_s << 'h ' if h >= 1
  str << m.to_s << 'm ' if m >= 1
  str << s.to_s << 's ' if s > 0

  return str.join
  
end

.timestamp(ts) ⇒ Object

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rcl/timestamp.rb', line 106

def self.timestamp(ts)
  raise ArgumentError, 'nil ts' if ts.nil?
  raise ArgumentError, 'invalid ts class' if ts.class != Time

  str = []

  str << '0' if ts.hour < 10
  str << ts.hour
  str << '0' if ts.min < 10
  str << ts.min
  str << '0' if ts.sec < 10
  str << ts.sec

  str.join
end

.versionObject



11
# File 'lib/rcl.rb', line 11

def self.version() RCL::VERSION end