Skip to content
Collection of useful ruby code snippets
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/gadgeto
spec
test
.gitignore
.rspec
.travis.yml
ChangeLog.markdown
Gemfile
LICENSE.txt
README.md
Rakefile
VERSION
gadgeto.gemspec

README.md

Gadgeto

Build Status Dependency Status Code Climate

Collection of ruby code snippets.

Usage

All functionality is loaded issuing:

require 'gadgeto/all'

If you plan to use only a handful of snippets, it is recommended to require explicitly each snippet:

require 'gadgeto/<snippet>'

For example:

require 'gadgeto/dslable' # loads Gadgeto::Dslable

Overview

Gadgeto::Domain

require 'gadgeto/domain'

Gadgeto::Domain.valid?("de")         #=> true
Gadgeto::Domain.valid?("test.de")    #=> true
Gadgeto::Domain.valid?("-.test.de")  #=> false

domain = Gadgeto::Domain.new("m.test.de")
domain.third_level_domain?           #=> true

Gadgeto::Dslable

require 'gadgeto/dslable'

class Foo
  include Gadgeto::Dslable
  include Gadgeto::Dslable::Display

  dslable_method :item, :key, '*arguments'

  def inspect
    attributes[:key]
  end
end

f = Foo.new

f.draw do
  item 'home', :baem => :bum do
    item 'terms'
    item 'imprint'
  end

  item 'products' do
    item 'kitchen' do
      item 'forks'
    end
  end
end

f.display :items
f.items[0].attributes[:key] #=> "home"

Gadgeto::Email

require 'gadgeto/email'

Gadgeto::Email.valid?("user@example.com")      #=> true
Gadgeto::Email.valid?("user+name@example.com") #=> true

Gadgeto::SanitizeFilename (Module)

require 'gadgeto/sanitize_filename'

obj = Object.new
obj.extend(Gadgeto::SanitizeFilename)
obj.sanitize_filename("foo bar.zip") #=> "foo_bar.zip"

Gadgeto::TimeOfDay

require 'gadgeto/time_of_day'

Gadgeto::TimeOfDay.valid?("09:15")   #=> true

t = Gadgeto::TimeOfDay.new("08:30")  #=> 08:30
t.hour                               #=> 8
t.minute                             #=> 30
t.to_i                               #=> 480
t.add_minutes(30)                    #=> 09:00

t1 = Gadgeto::TimeOfDay.new("08:30") #=> 08:30
t2 = Gadgeto::TimeOfDay.new("09:30") #=> 09:30
t1 < t2                              #=> true
t1 > t2                              #=> false
t1.minutes_till(t2)                  #=> 60
t1 == t2                             #=> false

Gadgeto::VideoUrl

require 'gadgeto/video_url'

Gadgeto::VideoUrl.valid?("http://vimeo.com/11384488") #=> true
Gadgeto::VideoUrl.supported_services                  #=> [:youtube, :vimeo]

video_url = Gadgeto::VideoUrl.new('http://www.youtube.com/watch?v=0zM3nApSvMg')
video_url.valid?  #=> true
video_url.service #=> :youtube
video_url.id      #=> "0zM3nApSvMg"

Contributors

See https://github.com/avarteqgmbh/gadgeto/contributors

Something went wrong with that request. Please try again.