Class: String

Inherits:
Object show all
Defined in:
lib/basecamper.rb

Overview

Core extensions

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/basecamper.rb', line 300

def blank?
  empty?
end

#capitalize_all(separator = " ") ⇒ Object



296
297
298
# File 'lib/basecamper.rb', line 296

def capitalize_all(separator = " ")
  split(" ").map {|s| s.capitalize}.join(" ")
end

#dashifyObject



304
305
306
# File 'lib/basecamper.rb', line 304

def dashify
  self.tr '_', '-'
end

#to_timeObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/basecamper.rb', line 280

def to_time
  matches = self.match(/^(\d\d?)(:\d\d)?(am?|pm?)?$/i)
  return unless matches
  
  hour = matches[1].to_i
  minutes = matches[2] ? matches[2].gsub(/:/, "").to_i : 0
  meridian = matches[3]
  
  return unless hour > 0
  hour += 12 if meridian =~ /^p/ and hour < 12
  return unless hour <= 24
  
  now = Time.now
  Time.mktime(now.year, now.month, now.day, hour, minutes)
end

#undashifyObject



308
309
310
# File 'lib/basecamper.rb', line 308

def undashify
  self.tr '-', '_'
end