Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/params/string.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_to(type) ⇒ Object



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

def self.convert_to(type)
    table = {
        String => :to_s,
        Symbol => :to_sym,
        Integer => :to_i,
        Float => :to_f,
        Date => :to_date,
        DateTime => :to_datetime,
        Time => :to_time
    }

    table[type]
end

Instance Method Details

#to_dateObject



18
19
20
# File 'lib/sinatra/params/string.rb', line 18

def to_date
    Date.parse(self)
end

#to_datetimeObject



26
27
28
# File 'lib/sinatra/params/string.rb', line 26

def to_datetime
    DateTime.parse(self)
end

#to_timeObject



22
23
24
# File 'lib/sinatra/params/string.rb', line 22

def to_time
    self.to_datetime.to_time
end