Skip to content

Instantly share code, notes, and snippets.

@syntacticsugar
Created February 22, 2012 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syntacticsugar/1885913 to your computer and use it in GitHub Desktop.
Save syntacticsugar/1885913 to your computer and use it in GitHub Desktop.
Samantha
require ""
require ""
require ""
class Samantha
def hallooo
end
end
class Samantha::Translator
def initialize(language)
@language = language
end
def hi
end
end
class Samantha::Define
def initialize(palabra)
end
end
# in this class i'm going to extract the user's name and save it as a variable, so Samantha can respond by invoking the user's name if she so wishes.
# if i were more sophisticaed at ruby, i would give the user three or four options of their names, as friends in real life call each other by multiple nicknames.
# then i would randomize, via Ruby (Math.random?) the names so Samantha responds with any of the random names in her responses. i know i can create an array of names with ruby, and then randomly pick elements of the array.
class Prenom
attr_accessor :name1, :name2, :name3 # not sure if this is doing it correctly....
def initialize(*prenom)
prenom = $STDIN.gets.capitalize.to_a # trying to create an array of capitalized names
@@prenom = prenom
end
def randomizer # and so begins here my randomizer for the names
mixed_names = @@prenom.replace(prenom.sort_by {rand}) # trying to create array of mixed names
end #end randomizer
def set_name=(*whatevernames)
# hm, a setter method
end
def get_name=(*whatevernames)
# because samantha has to be able to read/get a random name
end
# hm... also need a way to edit/add/delete existing names... this is a bit much though.
end #end class
Gem::Specification.new do |s|
s.name = 'samantha'
s.version = '0.0.0'
s.date = '2012-01-16'
s.summary = "Hey... it's Samantha. What do you need?"
s.description = "Samantha is your pal who defines words for you when you are lazy :P Simply run 'samantha define <word>'"
s.authors = ["Romy <3"]
s.email = 'romy@romyromy.com'
s.files = ["lib/sammy.rb"]
s.homepage =
'http://rubygems.org/gems/samantha'
end
require 'nokogiri'
require 'open-uri'
unless ARGV[0] # obligatory no-argument check
puts "It kinda helps to provide the word in question! :)"
puts "FYI usage is as follows: ruby explain.rb <word> to define>"
# puts "usage: "samantha define <word>"
exit
end
word = ARGV[0].strip.downcase
##################### <note> following didn't work well, gave me headaches
# url = "http://dictionary.reference.com/search?q=#{word}"
# doc = Nokogiri::HTML(open("http://dictionary.cambridge.org/dictionary/british/#{word}_1?q=#{word}"))
#doc.css('div.mw-content-ltr ol li').each do |definition|
# puts definition.content
#end
##################### </note>
doc = Nokogiri::HTML(open("http://en.wiktionary.org/wiki/#{word}"))
doc.xpath('//div[@class="mw-content-ltr"]/ol[1]/li').each do |definition|
puts definition.content
end
##################### <note>: following didn't work with dictionary.com, so i scrapped it
#begin
# open url do |source|
# source.each_line do |result|
# if result =~ /No results found/ # ruby's awesome pattern matcher RAWRRrrrRR!!!!
# puts "Ooof... either you've made a spelling blooper or our trusty dictionary is sore out of the loop." # spelling error
# exit
# end
# if result =~ /(1\.)<\/td><td valign="top">(.*)<\/td/ # regexxxxx
# puts "Mmmkay, here's what I fetched. Enjoy."
# puts "\n#{$1} #{$2}"
# exit
# end
#end
#
#end
##################### </note>
##################### <note> possible error message
puts "Hmm... I'm afraid I didn't get much sleep last night.. :/ Can't manage to perform for now. Apologies..."
##################### </note> possible error message
################## <note> what am i trying to here?
#rescue => e
# puts "Hate to break it to you but there's been an error. Give it another shot."
# puts e
#end
################## </note>
require 'nokogiri'
require 'open-uri'
unless ARGV[0] # obligatory no-argument check
puts "It kinda helps to provide the word in question! :)"
puts "FYI usage is as follows: ruby explain.rb <word> to define>"
# puts "usage: "samantha define <word>"
exit
end
word = ARGV[0].strip.downcase
##################### <note> following didn't work well, gave me headaches
# url = "http://dictionary.reference.com/search?q=#{word}"
# doc = Nokogiri::HTML(open("http://dictionary.cambridge.org/dictionary/british/#{word}_1?q=#{word}"))
#doc.css('div.mw-content-ltr ol li').each do |definition|
# puts definition.content
#end
##################### </note>
doc = Nokogiri::HTML(open("http://en.wiktionary.org/wiki/#{word}"))
doc.xpath('//div[@class="mw-content-ltr"]/ol[1]/li').each do |definition|
puts definition.content
end
##################### <note>: following didn't work with dictionary.com, so i scrapped it
#begin
# open url do |source|
# source.each_line do |result|
# if result =~ /No results found/ # ruby's awesome pattern matcher RAWRRrrrRR!!!!
# puts "Ooof... either you've made a spelling blooper or our trusty dictionary is sore out of the loop." # spelling error
# exit
# end
# if result =~ /(1\.)<\/td><td valign="top">(.*)<\/td/ # regexxxxx
# puts "Mmmkay, here's what I fetched. Enjoy."
# puts "\n#{$1} #{$2}"
# exit
# end
#end
#
#end
##################### </note>
##################### <note> possible error message
puts "Hmm... I'm afraid I didn't get much sleep last night.. :/ Can't manage to perform for now. Apologies..."
##################### </note> possible error message
################## <note> what am i trying to here?
#rescue => e
# puts "Hate to break it to you but there's been an error. Give it another shot."
# puts e
#end
################## </note>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment