Class: Brain

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Brain.



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

def initialize(sheldon_data_dir, opts = {})
  @brain_location = sheldon_data_dir
  @memory = opts[:memory] || Memory.new(@brain_location)
end

Instance Attribute Details

#memoryObject (readonly)

Returns the value of attribute memory.



3
4
5
# File 'lib/sheldon/brain.rb', line 3

def memory
  @memory
end

Instance Method Details

#has_cue?(recall_cue) ⇒ Boolean

Returns:



28
29
30
# File 'lib/sheldon/brain.rb', line 28

def has_cue?(recall_cue)
  memory.has_cue?(recall_cue)
end

#learn(recall_cue, abs_learn_path) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/sheldon/brain.rb', line 11

def learn(recall_cue, abs_learn_path)
  cell = get_cell(recall_cue)
  FileUtils.mkdir_p(cell)
  FileUtils.mv(abs_learn_path, cell)
  entry = { filepath: remove_home(abs_learn_path) }
  memory.add(recall_cue, entry)
end

#list_cuesObject



36
37
38
# File 'lib/sheldon/brain.rb', line 36

def list_cues
  memory.list_cues
end

#recall(recall_cue) ⇒ Object



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

def recall(recall_cue)
  entry = memory.recall(recall_cue)
  destination_path = add_home(entry[:filepath])
  destination_dir = File.dirname(destination_path)
  FileUtils.mkdir_p(destination_dir) unless File.directory?(destination_dir)
  source_cell = get_cell(recall_cue)
  FileUtils.ln_s(read_cell(source_cell), destination_path, force: true)
end

#sizeObject



32
33
34
# File 'lib/sheldon/brain.rb', line 32

def size
  memory.size
end