Created
March 11, 2010 03:43
-
-
Save codejoust/328790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
class Person | |
def initialize(name, email) | |
@name, @email = name, email.gsub('|', '').gsub('*','.') | |
end | |
def show_name | |
@name | |
end | |
def visit(site) | |
if (@data["portfolio"].match(/http:\/\//) && system("firefox #{site}")) | |
true | |
else | |
gtk.show_dialog "Visit #{site} for info." | |
end | |
end | |
def email(message, from) | |
begin | |
require 'net/smtp' | |
Net::SMTP.start('localhost',25) do |emailer| | |
emailer.send_message(message, from, @email) | |
end | |
rescue | |
false | |
end | |
end | |
def format(string) | |
string.to_s.capitalize.gsub(/_|-/, ' ') | |
end | |
def my_data | |
{:name => @name, :email => @email} | |
end | |
end | |
class Iain < Person | |
def initialize(*args) | |
super(*args) | |
setup_iain | |
yield self if block_given? | |
end | |
def setup_iain | |
@data = \ | |
{"i like to be" => 'outside running around!', | |
"favorite programming language" => 'ruby', | |
"my portfolio site is" => "codejoust.com"} | |
@music = \ | |
{:genre => %w{rock-roll techno baroque electronica celtic}, | |
:artist => "coldplay bach enya john-mayer".split(' ')} | |
@twitter = 'codejoust' | |
end | |
def about_me | |
@data.map do |thing, like| | |
format(thing) + ': ' + format(like) | |
end.join("\n") | |
end | |
def music | |
@music.to_a.map{ |name, val| (name.to_s + ' ' + val.join(", ")) }\ | |
.join("\n") | |
end | |
def full_profile | |
my_data.map{|name,val| | |
format(name) + ': ' + format(val) + "\n" | |
} | |
end | |
def my_data | |
{:music=> music, :about_me=> about_me}.merge(super) | |
end | |
def twitter | |
full_profile.merge({:twitter => @twitter}) | |
end | |
end | |
if __FILE__ == $0 | |
iain = Iain.new('Iain Nash', 'me|@|iain*in') do |person| | |
puts [person.show_name, | |
person.full_profile, | |
"Thanks for reading this, ☺ #{Time.now.strftime('%Y')}"].join("\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment