Module: ActiveSupport::CoreExtensions::String::Conversions

Defined in:
lib/rails_appengine/active_support_conversions.rb

Overview

Converting strings to other objects

Instance Method Summary collapse

Instance Method Details

#ordObject

‘a’.ord == ‘a’ for Ruby 1.9 forward compatibility.



9
10
11
# File 'lib/rails_appengine/active_support_conversions.rb', line 9

def ord
  self[0]
end

#to_dateObject



22
23
24
25
26
27
28
29
# File 'lib/rails_appengine/active_support_conversions.rb', line 22

def to_date
  begin
    ::Date.new(*::Date._parse(self, false).
        values_at(:year, :mon, :mday))
  rescue
    nil
  end
end

#to_datetimeObject



30
31
32
33
34
35
36
37
38
# File 'lib/rails_appengine/active_support_conversions.rb', line 30

def to_datetime
  begin
    ::DateTime.civil(*::Date._parse(self, false).
        values_at(:year, :mon, :mday, :hour, :min, :sec).
        map { |arg| arg || 0 })
  rescue
    nil
  end
end

#to_time(form = :utc) ⇒ Object

Form can be either :utc (default) or :local.



13
14
15
16
17
18
19
20
21
# File 'lib/rails_appengine/active_support_conversions.rb', line 13

def to_time(form = :utc)
  begin
    ::Time.send("#{form}_time", *::Date._parse(self, false).
        values_at(:year, :mon, :mday, :hour, :min, :sec).
        map { |arg| arg || 0 })
  rescue
    nil
  end
end