Top Level Namespace

Defined Under Namespace

Modules: Morpheus Classes: NilClass

Instance Method Summary collapse

Instance Method Details

#display_appliance(name, url) ⇒ Object



45
46
47
# File 'lib/morpheus/formatters.rb', line 45

def display_appliance(name, url)
  "#{name} - #{url}"
end

#format_date(dt, options = {}) ⇒ Object



32
33
34
# File 'lib/morpheus/formatters.rb', line 32

def format_date(dt, options={})
  format_dt(dt, options.merge({local: true}))
end

#format_dt(dt, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/morpheus/formatters.rb', line 18

def format_dt(dt, options={})
  dt = parse_time(dt)
  return "" if dt.nil?
  if options[:local]
    dt = dt.getlocal
  end
  format = options[:format] || "%x %I:%M %p %Z"
  return dt.strftime(format)
end

#format_dt_as_param(dt) ⇒ Object



40
41
42
43
# File 'lib/morpheus/formatters.rb', line 40

def format_dt_as_param(dt)
  dt = dt.getutc
  format_dt(dt, {format: "%Y-%m-%d %X"})
end

#format_local_date(dt, options = {}) ⇒ Object



36
37
38
# File 'lib/morpheus/formatters.rb', line 36

def format_local_date(dt, options={})
  format_dt(dt, {local: true, format: "%x"}.merge(options))
end

#format_local_dt(dt, options = {}) ⇒ Object



28
29
30
# File 'lib/morpheus/formatters.rb', line 28

def format_local_dt(dt, options={})
  format_dt(dt, {local: true}.merge(options))
end

#iso8601(dt) ⇒ Object



49
50
51
# File 'lib/morpheus/formatters.rb', line 49

def iso8601(dt)
  dt.instance_of(Time) ? dt.iso8601 : "#{dt}"
end

#parse_time(dt) ⇒ Object

returns an instance of Time



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/morpheus/formatters.rb', line 4

def parse_time(dt)
  if dt.nil? || dt == '' || dt.to_i == 0
    return nil
  elsif dt.is_a?(Time)
    return dt
  elsif dt.is_a?(String)
    return Time.parse(dt)
  elsif dt.is_a?(Numeric)
    return Time.at(dt)
  else
    raise "bad argument type for parse_time() #{dt.class} #{dt.inspect}"
  end
end