public
Created

Samantha

  • Download Gist
lib/old_attempt_for_translation_feature.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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
lib/prenom.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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
lib/samantha.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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>
samantha.gemspec
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
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
samantha.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.