Class: Sheldon

Inherits:
Object
  • Object
show all
Defined in:
lib/sheldon/sheldon.rb

Constant Summary collapse

VERSION =
"0.4.0".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheldon_data_dir, opts = {}) ⇒ Sheldon



7
8
9
10
11
12
13
14
# File 'lib/sheldon/sheldon.rb', line 7

def initialize(sheldon_data_dir, opts = {})
  unless Dir.exists?(sheldon_data_dir)
    raise MissingDataDirectoryException, "The data directory (#{sheldon_data_dir}) doesn't exist. Please create the directory or set an alternative using the $SHELDON_DATA_DIR environment variable."
  end

  @brain = opts[:brain] || Brain.new(sheldon_data_dir)
  @builder = opts[:builder] || Builder.new
end

Instance Attribute Details

#brainObject (readonly)

Returns the value of attribute brain.



5
6
7
# File 'lib/sheldon/sheldon.rb', line 5

def brain
  @brain
end

#builderObject (readonly)

Returns the value of attribute builder.



5
6
7
# File 'lib/sheldon/sheldon.rb', line 5

def builder
  @builder
end

Instance Method Details

#build(abs_learn_path) ⇒ Object



16
17
18
# File 'lib/sheldon/sheldon.rb', line 16

def build(abs_learn_path)
  builder.build(abs_learn_path)
end

#forget(recall_cue) ⇒ Object



34
35
36
37
# File 'lib/sheldon/sheldon.rb', line 34

def forget(recall_cue)
  raise "Cue '#{recall_cue}' could not be found." unless brain.has_cue?(recall_cue)
  brain.forget(recall_cue)
end

#learn(recall_cue, abs_learn_path) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/sheldon/sheldon.rb', line 20

def learn(recall_cue, abs_learn_path)
  raise "recall cue cannot be empty." if recall_cue.strip.empty?
  if brain.has_cue?(recall_cue)
    raise "This cue has already been used."
  else
    brain.learn(recall_cue, abs_learn_path)
  end
end

#list_cuesObject



39
40
41
# File 'lib/sheldon/sheldon.rb', line 39

def list_cues
  brain.list_cues
end

#recall(recall_cue) ⇒ Object



29
30
31
32
# File 'lib/sheldon/sheldon.rb', line 29

def recall(recall_cue)
  raise "Cue '#{recall_cue}' could not be found." unless brain.has_cue?(recall_cue)
  brain.recall(recall_cue)
end

#recalled?(recall_cue) ⇒ Boolean



43
44
45
46
# File 'lib/sheldon/sheldon.rb', line 43

def recalled?(recall_cue)
  raise "Cue '#{recall_cue}' could not be found." unless brain.has_cue?(recall_cue)
  brain.recalled?(recall_cue)
end