204 Big Words

Description

Wassup Rubyists,

This weeks quiz was submitted by Alan.

Write a method that will return a large version of a string you provide it.

puts big_word('BIGWORD')

######  #######  #####  #     #  #####  ######  ######  
#     #    #    #       #     # #     # #     # #     #
######     #    #   ### #  #  # #     # ######  #     #
#     #    #    #     # #  #  # #     # #    #  #     #
######  #######  #####   ## ##   #####  #     # ######  

For extra credit you may include additional font styles, such as italic.

puts big_word('BIGWORD', 'i')

   ######  #######  #####  #     #  #####  ######  ######  
  #     #    #    #       #     # #     # #     # #     #
 ######     #    #   ### #  #  # #     # ######  #     #
#     #    #    #     # #  #  # #     # #    #  #     #
######  #######  #####   ## ##   #####  #     # ######  

Have Fun!

Summary

This week’s quiz was solved by Matthias Reitinger. Let’s check out the solution:

require 'rubygems'
require 'text'

def big_word(str, fontfile='banner.flf')
  font = Text::Figlet::Font.new(fontfile)
  figlet = Text::Figlet::Typesetter.new(font)
  figlet[str]
end

Matthias uses the Text gem to display fonts using the FIGlet format. The big_word method takes an optional font file parameter to allow different styles. It operates by loading the file, creating a FIGlet Typesetter from the font, and passing the input string to the Typesetter. An easy to use and straightforward library.

There are a couple of prerequisites to use the program, though. You’ll need the Text gem and a font file. I found that when installing the gem, I needed to use the command gem install Text; the command with lowercase text wouldn’t work for me. Matthias also links to the FIGlet font database where there are some amazing fonts available.

In addition to FIGlet, the Text gem includes many other useful libraries like Metaphone and Soundex. The Metaphone component of the Text gem was used way back on Quiz #140 to sound out T-Shirts.

Thank you, Matthias, for sharing this useful library.

 ____            __                  _____                         
/\  _`\         /\ \                /\  __`\          __           
\ \ \L\ \  __  __\ \ \____  __  __  \ \ \/\ \  __  __/\_\  ____    
 \ \ ,  / /\ \/\ \ \ '__`\/\ \/\ \   \ \ \ \ \/\ \/\ \/\ \/\_ ,`\  
  \ \ \\ \\ \ \_\ \ \ \L\ \ \ \_\ \   \ \ \\'\\ \ \_\ \ \ \/_/  /_ 
   \ \_\ \_\ \____/\ \_,__/\/`____ \   \ \___\_\ \____/\ \_\/\____\
    \/_/\/ /\/___/  \/___/  `/___/> \   \/__//_/\/___/  \/_/\/____/
                               /\___/                              
                               \/__/                               

Saturday, May 09, 2009