Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ moved old project

  • Loading branch information...
commit 8b8ee9c05cba56997203f69c2157281ddaaf3267 1 parent 00ab79d
@floere floere authored
Showing with 171 additions and 50 deletions.
  1. +1 −0  .gitignore
  2. 0  bin/james
  3. +22 −0 james.gemspec
  4. +1 −0  lib/james.rb
  5. +9 −0 lib/james/controller.rb
  6. 0  { → old}/README
  7. 0  { → old}/config/README
  8. 0  { → old}/config/names.yml
  9. 0  { → old}/config/sentences.yml
  10. 0  { → old}/config/voices.yml
  11. 0  { → old}/configurator.rb
  12. 0  { → old}/dialogue.rb
  13. +16 −16 { → old}/dialogue_extension.rb
  14. 0  { → old}/dialogue_frontend.rb
  15. 0  { → old}/dialogue_plugin.rb
  16. BIN  old/dialogues/.DS_Store
  17. 0  { → old}/dialogues/joke/README
  18. 0  { → old}/dialogues/joke/init.rb
  19. 0  { → old}/dialogues/joke/lib/joke_dialogue.rb
  20. 0  { → old}/dialogues/phonebook/init.rb
  21. 0  { → old}/dialogues/phonebook/lib/phonebook.rb
  22. 0  { → old}/dialogues/phonebook/lib/phonebook_dialogue.rb
  23. 0  { → old}/dialogues/phonebook/test/test_phonebook.rb
  24. 0  { → old}/dialogues/quote/README
  25. 0  { → old}/dialogues/quote/init.rb
  26. 0  { → old}/dialogues/quote/lib/quote_dialogue.rb
  27. 0  { → old}/dialogues/quote/lib/quote_of_the_day.rb
  28. 0  { → old}/dialogues/quote/test/test_quote_of_the_day.rb
  29. BIN  old/dialogues/sbb/.DS_Store
  30. 0  { → old}/dialogues/sbb/README
  31. 0  { → old}/dialogues/sbb/init.rb
  32. 0  { → old}/dialogues/sbb/lib/hpricot_finder.rb
  33. 0  { → old}/dialogues/sbb/lib/sbb.rb
  34. 0  { → old}/dialogues/sbb/lib/sbb_dialogue.rb
  35. 0  { → old}/dialogues/sbb/lib/sbb_finder.rb
  36. 0  { → old}/dialogues/sbb/lib/scrapi_finder.rb
  37. 0  { → old}/dialogues/sbb/lib/scrubyt_finder.rb
  38. 0  { → old}/dialogues/sbb/lib/test.html
  39. 0  { → old}/dialogues/sbb/test/test.html
  40. 0  { → old}/dialogues/sbb/test/test_sbb.rb
  41. 0  { → old}/dialogues/time/README
  42. 0  { → old}/dialogues/time/init.rb
  43. 0  { → old}/dialogues/time/lib/time_dialogue.rb
  44. +46 −0 old/hello_world.rb
  45. 0  { → old}/initializer.rb
  46. +34 −34 { → old}/main_dialogue.rb
  47. BIN  old/rubyscript2exe/.DS_Store
  48. 0  { → old}/rubyscript2exe/CHANGELOG
  49. 0  { → old}/rubyscript2exe/LICENSE
  50. 0  { → old}/rubyscript2exe/README
  51. 0  { → old}/rubyscript2exe/SUMMARY
  52. 0  { → old}/rubyscript2exe/VERSION
  53. 0  { → old}/rubyscript2exe/eee.ico
  54. 0  { → old}/rubyscript2exe/eee.o
  55. 0  { → old}/rubyscript2exe/eee.pas
  56. 0  { → old}/rubyscript2exe/eee.rc
  57. 0  { → old}/rubyscript2exe/eee_darwin
  58. 0  { → old}/rubyscript2exe/ev/dependencies.rb
  59. 0  { → old}/rubyscript2exe/ev/ftools.rb
  60. 0  { → old}/rubyscript2exe/ev/oldandnewlocation.rb
  61. 0  { → old}/rubyscript2exe/hello.rb
  62. 0  { → old}/rubyscript2exe/init.rb
  63. 0  { → old}/rubyscript2exe/require2lib.rb
  64. 0  { → old}/rubyscript2exe/rubyscript2exe.rb
  65. 0  { → old}/rubyscript2exe/tar2rubyscript.rb
  66. 0  { → old}/test.html
  67. 0  { → old}/test/dummy_frontend.rb
  68. 0  { → old}/test/test_dialogue.rb
  69. 0  { → old}/test/test_helper.rb
  70. +42 −0 test_project/joke_dialogue.rb
View
1  .gitignore
@@ -0,0 +1 @@
+*.gem
View
0  bin/james
No changes.
View
22 james.gemspec
@@ -0,0 +1,22 @@
+# encoding: utf-8
+#
+
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::CURRENT
+
+ s.name = 'james'
+ s.version = '0.0.1'
+
+ s.author = 'Florian Hanke'
+ s.email = 'florian.hanke+james@gmail.com'
+
+ s.homepage = 'http://floere.github.com/james'
+
+ s.description = 'Modular Electronic Butler. Add Dialog(ue)s to it to add more abilities to it.'
+ s.summary = 'James: Modular Electronic Butler.'
+
+ s.files = Dir["lib/**/*.rb"]
+ s.test_files = Dir["spec/**/*_spec.rb"]
+
+ s.add_development_dependency 'rspec'
+end
View
1  lib/james.rb
@@ -0,0 +1 @@
+module James end
View
9 lib/james/controller.rb
@@ -0,0 +1,9 @@
+module James
+
+ #
+ #
+ class Controller
+
+ end
+
+end
View
0  README → old/README
File renamed without changes
View
0  config/README → old/config/README
File renamed without changes
View
0  config/names.yml → old/config/names.yml
File renamed without changes
View
0  config/sentences.yml → old/config/sentences.yml
File renamed without changes
View
0  config/voices.yml → old/config/voices.yml
File renamed without changes
View
0  configurator.rb → old/configurator.rb
File renamed without changes
View
0  dialogue.rb → old/dialogue.rb
File renamed without changes
View
32 dialogue_extension.rb → old/dialogue_extension.rb
@@ -8,30 +8,30 @@
# if a state is entered, enter_#{state_name} is called
# if a state is exited, exit_#{state_name} is called
class DialogueExtension < Dialogue
-
+
attr_reader :state
-
+
alias :old_initialize :initialize
-
+
# every subclass of this class automatically has its state set to :entry on creation
# def initialize(*args)
# puts "Resetting ", self.name, "\n"
# reset
# old_initialize(*args)
# end
-
+
# # automatically adds a hook phrase
# # meaning: adds a move from :awake to this hook word
# # and also a method
def initialize
# reset
end
- #
+ #
# # TODO improve this such that reset doesn't need to be called in each initializer!
def reset
@state = :entry
end
-
+
# TODO think about saying something after each method call though like this it is kept simple which is good
def hear(phrase)
# if next state
@@ -44,24 +44,24 @@ def hear(phrase)
# call entry method
send("enter_#{@state}".intern) if respond_to?("enter_#{@state}")
end
-
+
# next possible phrases
# TODO splat
def expects
self.class.moves[@state].keys
end
-
+
def next_state(phrase)
self.class.moves[@state][phrase] if self.class.moves[@state]
end
-
+
# returns the possible states of this dialogue
def self.possible_states
self.moves.keys
end
-
+
# metaprog
-
+
# hook words - these define when this dialogue is entered
# adds a hooks method
# TODO get hooks from yaml file
@@ -84,18 +84,18 @@ class <<self
end
end
end
-
+
# initial state
def self.initial_state(initial)
self.class_eval do
- # add accessor for
+ # add accessor for
class <<self
attr_accessor :initial
end
self.initial = initial
end
end
-
+
# state definitions like
# state :name, { moves }
def self.state(name, moves)
@@ -105,7 +105,7 @@ def self.state(name, moves)
# split arrays here instead of handling later specifically
# can change the implementation later if needed
moves.each do |words,state|
- words.each do |word|
+ [*words].each do |word|
self.moves[name][word] = state
end
end
@@ -115,5 +115,5 @@ def self.state(name, moves)
end
# puts "#{self.name} === #{self.moves.inspect}"
end
-
+
end
View
0  dialogue_frontend.rb → old/dialogue_frontend.rb
File renamed without changes
View
0  dialogue_plugin.rb → old/dialogue_plugin.rb
File renamed without changes
View
BIN  old/dialogues/.DS_Store
Binary file not shown
View
0  dialogues/joke/README → old/dialogues/joke/README
File renamed without changes
View
0  dialogues/joke/init.rb → old/dialogues/joke/init.rb
File renamed without changes
View
0  dialogues/joke/lib/joke_dialogue.rb → old/dialogues/joke/lib/joke_dialogue.rb
File renamed without changes
View
0  dialogues/phonebook/init.rb → old/dialogues/phonebook/init.rb
File renamed without changes
View
0  dialogues/phonebook/lib/phonebook.rb → old/dialogues/phonebook/lib/phonebook.rb
File renamed without changes
View
0  dialogues/phonebook/lib/phonebook_dialogue.rb → old/dialogues/phonebook/lib/phonebook_dialogue.rb
File renamed without changes
View
0  dialogues/phonebook/test/test_phonebook.rb → old/dialogues/phonebook/test/test_phonebook.rb
File renamed without changes
View
0  dialogues/quote/README → old/dialogues/quote/README
File renamed without changes
View
0  dialogues/quote/init.rb → old/dialogues/quote/init.rb
File renamed without changes
View
0  dialogues/quote/lib/quote_dialogue.rb → old/dialogues/quote/lib/quote_dialogue.rb
File renamed without changes
View
0  dialogues/quote/lib/quote_of_the_day.rb → old/dialogues/quote/lib/quote_of_the_day.rb
File renamed without changes
View
0  dialogues/quote/test/test_quote_of_the_day.rb → old/dialogues/quote/test/test_quote_of_the_day.rb
File renamed without changes
View
BIN  old/dialogues/sbb/.DS_Store
Binary file not shown
View
0  dialogues/sbb/README → old/dialogues/sbb/README
File renamed without changes
View
0  dialogues/sbb/init.rb → old/dialogues/sbb/init.rb
File renamed without changes
View
0  dialogues/sbb/lib/hpricot_finder.rb → old/dialogues/sbb/lib/hpricot_finder.rb
File renamed without changes
View
0  dialogues/sbb/lib/sbb.rb → old/dialogues/sbb/lib/sbb.rb
File renamed without changes
View
0  dialogues/sbb/lib/sbb_dialogue.rb → old/dialogues/sbb/lib/sbb_dialogue.rb
File renamed without changes
View
0  dialogues/sbb/lib/sbb_finder.rb → old/dialogues/sbb/lib/sbb_finder.rb
File renamed without changes
View
0  dialogues/sbb/lib/scrapi_finder.rb → old/dialogues/sbb/lib/scrapi_finder.rb
File renamed without changes
View
0  dialogues/sbb/lib/scrubyt_finder.rb → old/dialogues/sbb/lib/scrubyt_finder.rb
File renamed without changes
View
0  dialogues/sbb/lib/test.html → old/dialogues/sbb/lib/test.html
File renamed without changes
View
0  dialogues/sbb/test/test.html → old/dialogues/sbb/test/test.html
File renamed without changes
View
0  dialogues/sbb/test/test_sbb.rb → old/dialogues/sbb/test/test_sbb.rb
File renamed without changes
View
0  dialogues/time/README → old/dialogues/time/README
File renamed without changes
View
0  dialogues/time/init.rb → old/dialogues/time/init.rb
File renamed without changes
View
0  dialogues/time/lib/time_dialogue.rb → old/dialogues/time/lib/time_dialogue.rb
File renamed without changes
View
46 old/hello_world.rb
@@ -0,0 +1,46 @@
+framework 'AppKit'
+
+class AppDelegate
+ def applicationDidFinishLaunching(notification)
+ voice_type = "com.apple.speech.synthesis.voice.GoodNews"
+ @voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
+ end
+
+ def windowWillClose(notification)
+ puts "Bye!"
+ exit
+ end
+
+ def say_hello(sender)
+ @voice.startSpeakingString("Hello World!")
+ puts "Hello World!"
+ end
+end
+
+app = NSApplication.sharedApplication
+app.delegate = AppDelegate.new
+
+# window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100],
+# styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask,
+# backing:NSBackingStoreBuffered,
+# defer:false)
+# window.title = 'MacRuby: The Definitive Guide'
+# window.level = 3
+# window.delegate = app.delegate
+#
+# button = NSButton.alloc.initWithFrame([80, 10, 120, 80])
+# button.bezelStyle = 4
+# button.title = 'Hello World!'
+# button.target = app.delegate
+# button.action = 'say_hello:'
+#
+# window.contentView.addSubview(button)
+#
+# window.display
+# window.orderFrontRegardless
+
+app.delegate.applicationDidFinishLaunching nil
+
+app.delegate.say_hello app.delegate
+
+app.run
View
0  initializer.rb → old/initializer.rb
File renamed without changes
View
68 main_dialogue.rb → old/main_dialogue.rb
@@ -6,9 +6,9 @@
# has exactly two states, sleeping and awake
# from the awake state, extensions can be plugged in to be delegated to them
class MainDialogue < Dialogue
-
+
attr_accessor :state
-
+
def initialize(frontend)
load_names
load_sentences
@@ -34,7 +34,7 @@ def initialize(frontend)
}
}
end
-
+
# next possible phrases
# TODO refactor
# TODO categorize expects -> can display it differently in view
@@ -53,7 +53,7 @@ def expects
end
expected.flatten
end
-
+
# actual state of self or delegated
def state
if delegated?
@@ -61,12 +61,12 @@ def state
end
@state
end
-
+
# returns nil or something
def delegated?
@extension
end
-
+
def next_state(phrase)
state = next_overriding_state(phrase)
return state if state
@@ -74,12 +74,12 @@ def next_state(phrase)
return state if state
nil
end
-
+
# overriding means more important
def next_overriding_state(phrase)
@moves[@state][phrase]
end
-
+
def next_delegated_state(phrase)
if delegated?
return @extension.next_state(phrase)
@@ -89,31 +89,31 @@ def next_delegated_state(phrase)
return hooked_extension(phrase).class.initial
end
end
-
+
def hear(phrase)
puts "hearing '#{phrase}'"
-
+
# check for overriding phrases
if next_overriding_state(phrase)
# save old state
old_state = @state
# get next state
@state = next_overriding_state(phrase)
-
+
# call exit method
#exit_response = send("exit_#{old_state}".intern, phrase) if @state
send("exit_#{old_state}".intern, phrase) if old_state
#say(exit_response) if exit_response.instance_of? String and !exit_response.empty?
-
+
# exit extension
exit_extension
-
+
# send in between state message
# overrides enter_<state>
method_name = "from_#{old_state}_to_#{@state}"
in_between = respond_to? method_name
if in_between
- from_to_response = send(method_name.intern, phrase)
+ from_to_response = send(method_name.intern, phrase)
say(from_to_response) if from_to_response
return
end
@@ -125,7 +125,7 @@ def hear(phrase)
return
end
end
-
+
# if not overriding, check if in extension
if @extension || @extension = hooked_extension(phrase)
# if the delegate can answer, we are happy
@@ -135,19 +135,19 @@ def hear(phrase)
return
end
end
-
+
# if the phrase cannot be handled, say so and return to awake
# this only occurs in badly formed dialogues
say("I don't know what you mean.")
exit_extension
end
-
+
# exit the current extension and return to true awake state
def exit_extension
@extension.reset if @extension
@extension = nil
end
-
+
# TODO can be removed?
def hook?(phrase)
# check extensions for hooks
@@ -156,7 +156,7 @@ def hook?(phrase)
end
false
end
-
+
# gets the extension that includes the heard hook
def hooked_extension(phrase)
# check extensions
@@ -165,30 +165,30 @@ def hooked_extension(phrase)
end
nil
end
-
+
# delegate heard phrase to extension
def delegate(heard_phrase)
return @extension.send(:hear, heard_phrase)
end
-
+
# callback to frontend
def say(text)
puts "saying '#{text}'"
# refactor
@frontend.say(text)
end
-
+
# state methods
-
+
def from_sleeping_to_awake(phrase)
"#{phrase} here!"
end
-
+
def enter_sleeping
exit_extension
random_reply(@sentences['goes to sleep'])
end
-
+
def exit_sleeping(phrase)
if phrase == @male_name
@frontend.male
@@ -196,31 +196,31 @@ def exit_sleeping(phrase)
@frontend.female
end
end
-
+
def enter_awake
# randomize
@awake_time = Time.now
random_reply(@sentences['wakes up'])
end
-
+
def exit_awake(phrase)
@extension_time = Time.now
end
-
+
private
-
+
def configure_extensions
# which dialogue extension it is in right now
@extension = nil
# actual packs
- @extensions = []
+ @extensions = []
Dir['dialogues/**'].each do | dialogue_dir |
dialogue_dir.match('(.*)(\/)(.*)')
dialogue_file = $3 + '_dialogue'
extend_with dialogue_file.camelize.constantize.new
end
end
-
+
# extend the main dialogue
# later added extension methods will not override old phrases
def extend_with(extension)
@@ -229,7 +229,7 @@ def extend_with(extension)
# append extension to list of extensions
@extensions << extension
end
-
+
def load_names
yaml_names = ''
File.open(File.join(JAMES_ROOT, 'config/names.yml')) do |f| yaml_names << f.read end
@@ -237,11 +237,11 @@ def load_names
@male_name = names['male'] || 'james' # default
@female_name = names['female'] || 'jamie' # default
end
-
+
def load_sentences
yaml_sentences = ''
File.open(File.join(JAMES_ROOT, 'config/sentences.yml')) do |f| yaml_sentences << f.read end
@sentences = YAML.load(yaml_sentences)
end
-
+
end
View
BIN  old/rubyscript2exe/.DS_Store
Binary file not shown
View
0  rubyscript2exe/CHANGELOG → old/rubyscript2exe/CHANGELOG
File renamed without changes
View
0  rubyscript2exe/LICENSE → old/rubyscript2exe/LICENSE
File renamed without changes
View
0  rubyscript2exe/README → old/rubyscript2exe/README
File renamed without changes
View
0  rubyscript2exe/SUMMARY → old/rubyscript2exe/SUMMARY
File renamed without changes
View
0  rubyscript2exe/VERSION → old/rubyscript2exe/VERSION
File renamed without changes
View
0  rubyscript2exe/eee.ico → old/rubyscript2exe/eee.ico
File renamed without changes
View
0  rubyscript2exe/eee.o → old/rubyscript2exe/eee.o
File renamed without changes
View
0  rubyscript2exe/eee.pas → old/rubyscript2exe/eee.pas
File renamed without changes
View
0  rubyscript2exe/eee.rc → old/rubyscript2exe/eee.rc
File renamed without changes
View
0  rubyscript2exe/eee_darwin → old/rubyscript2exe/eee_darwin
File renamed without changes
View
0  rubyscript2exe/ev/dependencies.rb → old/rubyscript2exe/ev/dependencies.rb
File renamed without changes
View
0  rubyscript2exe/ev/ftools.rb → old/rubyscript2exe/ev/ftools.rb
File renamed without changes
View
0  rubyscript2exe/ev/oldandnewlocation.rb → old/rubyscript2exe/ev/oldandnewlocation.rb
File renamed without changes
View
0  rubyscript2exe/hello.rb → old/rubyscript2exe/hello.rb
File renamed without changes
View
0  rubyscript2exe/init.rb → old/rubyscript2exe/init.rb
File renamed without changes
View
0  rubyscript2exe/require2lib.rb → old/rubyscript2exe/require2lib.rb
File renamed without changes
View
0  rubyscript2exe/rubyscript2exe.rb → old/rubyscript2exe/rubyscript2exe.rb
File renamed without changes
View
0  rubyscript2exe/tar2rubyscript.rb → old/rubyscript2exe/tar2rubyscript.rb
File renamed without changes
View
0  test.html → old/test.html
File renamed without changes
View
0  test/dummy_frontend.rb → old/test/dummy_frontend.rb
File renamed without changes
View
0  test/test_dialogue.rb → old/test/test_dialogue.rb
File renamed without changes
View
0  test/test_helper.rb → old/test/test_helper.rb
File renamed without changes
View
42 test_project/joke_dialogue.rb
@@ -0,0 +1,42 @@
+require File.expand_path '../../lib/james'
+
+# Little parody on the existing OSX joke
+# telling system.
+#
+class JokeDialogue < Dialogue
+
+ initial_state :joke
+ hook_words 'tell me a funny thing', 'tell me a joke'
+ state :joke, { 'another one' => :joke }
+
+ def initialize
+ # remove!
+ # reset
+ end
+
+ def enter_joke
+ jokes = [
+ # 'One night, George W. Bush is tossing restlessly in his White House bed. He awakens to see George Washington standing by him Bush asks him, "George, what''s the best thing I can do to help the country?"
+ # "Set an honest and honorable example, just as I did," Washington advises, and then fades away...
+ # The next night, Bush is astir again, and sees the ghost of Thomas Jefferson moving through the darkened bedroom. Bush calls out, "Tom, please! What is the best thing I can do to help the country?"
+ # "Respect the Constitution, as I did," Jefferson advises, and dims from sight...
+ # The third night sleep still does not come for Bush. He awakens to see the ghost of FDR hovering over his bed. Bush whispers, "Franklin, What is the best thing I can do to help the country?"
+ # "Help the less fortunate, just as I did," FDR replies and fades into the mist...
+ # Bush isn''t sleeping well the fourth night when he sees another figure moving in the shadows. It is the ghost of Abraham Lincoln. Bush pleads, "Abe, what is the best thing I can do right now to help the country?"
+ # Lincoln replies, "Go see a play."',
+ # 'Two doctors are in the hallway complaining about nurse Nancy.
+ # "She\'s out of control!" the first doctor says. "She does everything backwards. Just last week I told her to give a man two milligrams of morphine every ten hours, she gave him 10 milligrams every two hours, he almost died!"
+ # "That\'s nothing," said the second doctor, "earlier this week I told her to give a man an enema every 24 hours, she tried to give him 24 enemas in one hour!"
+ # All of a sudden they heard a blood curldling scream from down the hallway.
+ # "OH MY GOD! I just realized that I told nurse Nancy to prick Mr. Smiths boil!"',
+ 'What do you say to a cow that crosses in front of your car? ... ... Mooove over.',
+ 'What\'s green, has 6 legs, and if it falls out of a tree and lands on you, it could hurt? ... ... A pool table.',
+ 'What is the one thing everybody in the world is doing at the same time? ... ... Growing older.',
+ 'How many hamburgers can you eat on an empty stomach? ... ... Only one or part of one, because after that, your stomach is no longer empty.',
+ 'What\'s the difference between a jeweler and a jailor? ... ... One sells watches, and the other watches cells.',
+ 'What did the elephant say to the naked man? ... ... How do you breathe through that thing?'
+ ]
+ random_reply(jokes)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.