Top 5 Most Useful Ruby Gems
Check out the top 5 most useful ruby gems that you may not have heard of!
Mailfactory
Mailfactory is a ruby library designed to allow the simple creation of emails. It offers the following features:
- Plain text and HTML body parts
- Simple attachments
- MIME-type guessing for attachments
- Attachments from arbitrary IO objects
- Custom headers
- RFC valid email generation
- Simple API
To Install:
gem install mailfactory
Example:
require 'rubygems'
require 'net/smtp'
require 'mailfactory'
#Connect to SMTP Server
smtp = Net::SMTP.new('mail.host.com', 25)
smtp.start('mydomain.com')
#Construct Mail Message
mail = MailFactory.new()
mail.to = 'foo@monkey.com'
mail.from = 'jason@dzone.com'
mail.subject = 'An email from Ruby'
mail.add_attachment('/path/to/file')
mail.html = "<h1>Hello From Ruby!</h1><p>Mailfactory is nice</p>"
#Construct SMTP Message
smtp.send_message mail.construct, 'foo@monkey.com', 'jason@dzone.com'
#Send this (and all other) message
smtp.finish()
Feed-Normalizer
Feed-Normalizer normalizes all RSS Feed formats into a generic class. This allows you to access the same properties from any RSS Feed it parses without worrying about the underlying format of the RSS source.
To Install:
gem install feed-normalizer
See Ruby RSS Aggregator for example code.
FasterCSV
FasterCSV is significantly faster than CSV and arguably has an improved CSV interface.
To Install
gem install fastercsv
Example:
require 'rubygems'
require 'fastercsv'
#Read a CSV File
FasterCSV.foreach('/path/to/file') do |row|
element1 = row[0]
element2 = row[2]
element3 = row[3]
end
#Write a CSV File
FasterCSV.open('/path/to/file') do |csv|
csv << ["an", "array", "of", "data"]
end
Bishop
Bishop is a Bayesian classifier library for Ruby. With Bishop you can effectively train your program to recognize any number of things.
To Install:
gem install bishop
Example:
require 'rubygems'
require 'bishop'
#Initialize the classifier
classifier = Bishop::Bayes.new
classifier.load('spam_or_no_spam.yml') if File.file?('spam_or_no_spam.yml')
#Train the classifier to recognize spam email
classifier.train('spam', 'Amazing results in a few weeks!')
classifier.train('spam', 'Get your free viagra!')
classifier.train('spam', 'A credit card offer!')
#Train the classifier to recognize legit email
classifier.train('not spam', 'Your payment update')
classifier.train('not spam', 'Scheduled Maintenance Reminder')
classifier.train('not spam', 'Can you pick the kids up today?')
#Save classication file so your program can learn
classifier.save('spam_or_no_spam.yml')
#Guess if an email is spam or not
guess = classifier.guess('How would you like a free sample of viagra?')
Linguistics
Linguistics is a generic, language-neutral framework for extending Ruby objects with linguistic methods. This is easily one of the coolest gems. There is simply so much you can do with the Linguistics module.
To Install:
gem install linguistics
Example:
require 'rubygems'
require 'linguistics'
"book".en.a
# => "a book"
"runs".en.present_participle
# => "running"
5.en.ordinal
# => "5th"
2004.en.numwords
# => "two thousand and four"
animals = %w{dog cow ox chicken goose goat cow dog rooster llama
pig goat dog cat cat dog cow goat goose goose ox alpaca}
puts "The farm has: " + animals.en.conjunction
# => The farm has: four dogs, three cows, three geese, three goats,
two oxen, two cats, a chicken, a rooster, a llama, a pig,
and an alpaca
- palmerj3's blog
- Login or register to post comments
- 7304 reads
- Flag as offensive
- Email this Blog entry
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






