Sha256: b44fc3133d8cd4638e15fa0dbc146b2deff52ad306fa0562ee7eb7b40036d6b2

Contents?: true

Size: 708 Bytes

Versions: 11

Compression:

Stored size: 708 Bytes

Contents

# A couple of Ruby extensions

class Date
  # Returns the date formatted with the format defined in Serious.date_format
  # and extended with the %o flag for ordinal day names.
  def formatted
    strftime(Serious.date_format.gsub("%o", day.ordinal))
  end
end

class Fixnum
  # Taken from toto
  def ordinal
    # 1 => 1st
    # 2 => 2nd
    # 3 => 3rd
    # ...
    case self % 100
      when 11..13; "#{self}th"
    else
      case self % 10
        when 1; "#{self}st"
        when 2; "#{self}nd"
        when 3; "#{self}rd"
        else "#{self}th"
      end
    end
  end
end

class String
  def slugize
    self.downcase.gsub(/[^a-z0-9\-]/, '-').squeeze('-').gsub(/^\-/, '').gsub(/\-$/, '')
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
serious-0.2.12 lib/ruby_ext.rb
serious-0.2.11 lib/ruby_ext.rb
serious-0.2.10 lib/ruby_ext.rb
serious-0.2.9 lib/ruby_ext.rb
serious-0.2.8 lib/ruby_ext.rb
serious-0.2.7 lib/ruby_ext.rb
serious-0.2.6 lib/ruby_ext.rb
serious-0.2.5 lib/ruby_ext.rb
serious-0.2.4 lib/ruby_ext.rb
serious-0.2.3 lib/ruby_ext.rb
serious-0.2.2 lib/ruby_ext.rb