shitou's blog 
Home About Feed | MIX BOY 塌客

Tags "gems"

23
Jul

[转载]5个有用的ruby gems by shitou

0

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:

  1. require 'rubygems'  
  2. require 'net/smtp'  
  3. require 'mailfactory'  
  4.   
  5. #Connect to SMTP Server  
  6. smtp = Net::SMTP.new('mail.host.com', 25)  
  7. smtp.start('mydomain.com')  
  8.   
  9. #Construct Mail Message   
  10. mail = MailFactory.new()  
  11. mail.to = 'foo@monkey.com'  
  12. mail.from = 'jason@dzone.com'  
  13. mail.subject = 'An email from Ruby'  
  14. mail.add_attachment('/path/to/file')  
  15. mail.html = "

    Hello From Ruby!

    Mailfactory is nice

    "
      
  16.   
  17. #Construct SMTP Message  
  18. smtp.send_message mail.construct, 'foo@monkey.com', 'jason@dzone.com'  
  19.   
  20. #Send this (and all other) message  
  21. smtp.finish()      
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 = "

Hello From Ruby!

Mailfactory is nice

"

#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

Example:

  1. require 'rubygems'  
  2. require 'feed-normalizer'  
  3.   
  4. #Define URL and Parse Feed  
  5. feed_url = 'http://rss.slashdot.org/Slashdot/slashdot'  
  6. rss = FeedNormalizer::FeedNormalizer.parse open(feed_url)  
  7.   
  8. #Quit if no articles  
  9. exit unless rss.entries.length > 0  
  10.   
  11. #Read entries  
  12. rss.entries.each do |entry|  
  13.     title = entry.title  
  14.     body = entry.content  
  15.     authors = entry.authors.join(', ') rescue ''  
  16.     entry_url = entry.urls.first  
  17.   
  18.     #Your Logic Here  
  19. end 

 

 

FasterCSV

FasterCSV is significantly faster than CSV and arguably has an improved CSV interface.

To Install
gem install fastercsv

Example:


  1. require 'rubygems'  
  2. require 'fastercsv'  
  3.   
  4. #Read a CSV File  
  5. FasterCSV.foreach('/path/to/file') do |row|  
  6.     element1 = row[0]  
  7.     element2 = row[2]  
  8.     element3 = row[3]  
  9. end  
  10.   
  11. #Write a CSV File  
  12. FasterCSV.open('/path/to/file') do |csv|  
  13.     csv << ["an", "array", "of", "data"]  
  14. end  
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:

  1. require 'rubygems'  
  2. require 'bishop'  
  3.       
  4. #Initialize the classifier  
  5. classifier = Bishop::Bayes.new  
  6. classifier.load('spam_or_no_spam.yml') if File.file?('spam_or_no_spam.yml')  
  7.   
  8. #Train the classifier to recognize spam email  
  9. classifier.train('spam', 'Amazing results in a few weeks!')  
  10. classifier.train('spam', 'Get your free viagra!')  
  11. classifier.train('spam', 'A credit card offer!')  
  12.   
  13. #Train the classifier to recognize legit email  
  14. classifier.train('not spam', 'Your payment update')  
  15. classifier.train('not spam', 'Scheduled Maintenance Reminder')  
  16. classifier.train('not spam', 'Can you pick the kids up today?')  
  17.   
  18. #Save classication file so your program can learn  
  19. classifier.save('spam_or_no_spam.yml')  
  20.   
  21. #Guess if an email is spam or not  
  22. guess = classifier.guess('How would you like a free sample of viagra?')  
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:

  1. require 'rubygems'  
  2. require 'linguistics'  
  3.   
  4. "book".en.a  
  5. # => "a book"  
  6.   
  7. "runs".en.present_participle  
  8. # => "running"  
  9.   
  10. 5.en.ordinal  
  11. # => "5th"  
  12.   
  13. 2004.en.numwords  
  14. # => "two thousand and four"  
  15.   
  16. animals = %w{dog cow ox chicken goose goat cow dog rooster llama  
  17. pig goat dog cat cat dog cow goat goose goose ox alpaca}  
  18. puts "The farm has: " + animals.en.conjunction  
  19.   
  20. # => The farm has: four dogs, three cows, three geese, three goats,  
  21. two oxen, two cats, a chicken, a rooster, a llama, a pig,  
  22. and an alpaca 
Tags: ruby,gems

2008-07-23 19:49:32, 844 reviews

send to mailbox

Your email:

Tags

U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • iPhone[17]
  • Erlang[4]
  • google[8]
  • 生活[38]
  • 音乐[11]
  • 电影[11]
  • linux[20]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[5]
  • ruby[18]
  • ruby on rails[27]
  • 开源[3]

Episode

  • iPhoneException
  • shell
  • thread
  • memcache

Recent Comments

  • comment6, http://www.freecodesource.com/user/pr...
  • comment7, viagra 100mg tablets, periwig, levitr...
  • comment5, prozac without prescription, :*), las...
  • comment2, viagra canada online, doors, lasix 20...
  • comment6, http://www.freecodesource.com/user/pr...
  • comment6, http://www.freecodesource.com/user/pr...
  • comment7, proscar flomax, <>], vicodin tablets,...
  • comment2, viagra medication, 2263, prilosec dia...
  • comment7, viagra sales australia, 401, oxycodon...
  • comment7, http://www.freecodesource.com/user/pr...

Popular Posts

  • MySQL Innodb备份
  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Lighttpd配置参数
  • iPhone上的HelloWorld终于跑起来了
  • Etag和Expire

Recommended Posts

  • Mai Kuraki -永远より ながく
  • U-ka saegusa IN db Final Best
  • Heaven Can Wait - Charlotte Gainsbou
  • Ruby遍历MemCached的key
  • Norah Jones - The fall
  • 请记得仰望梦想的姿势
  • Shell: 统计MySQL InnoDB表的大小
  • Rails Benchmark
  • 发送异常到邮箱
  • I Miss Nobody
  • Music4u, Vol. 1
  • my macbook
  • Mai Kuraki-Beautiful
  • 10首最伤情英文歌曲精选
  • Mai Kuraki - PUZZLE/Revive

Friends' blogs

  • levy
  • sphance
  • andreas

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 51224
  • 今天访问: 88
  • 日志: 172
  • 评论: 121
  • 音乐: 9
  • 用户: 150


 

just DO NOT support IE

close