Class: Brain
- Inherits:
-
Object
- Object
- Brain
- Defined in:
- lib/sheldon/brain.rb
Instance Attribute Summary collapse
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
Instance Method Summary collapse
- #forget(recall_cue) ⇒ Object
- #has_cue?(recall_cue) ⇒ Boolean
-
#initialize(sheldon_data_dir, opts = {}) ⇒ Brain
constructor
A new instance of Brain.
- #learn(recall_cue, abs_learn_path) ⇒ Object
- #list_cues ⇒ Object
- #recall(recall_cue) ⇒ Object
- #recalled?(recall_cue) ⇒ Boolean
- #size ⇒ Object
Constructor Details
Instance Attribute Details
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
3 4 5 |
# File 'lib/sheldon/brain.rb', line 3 def memory @memory end |
Instance Method Details
#forget(recall_cue) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/sheldon/brain.rb', line 28 def forget(recall_cue) entry = memory.recall(recall_cue) brain_path = brain_path_for_cue(recall_cue) destination_path = add_home(entry[:filepath]) FileUtils.rm_r(brain_path) FileUtils.rm_r(destination_path) memory.forget(recall_cue) end |
#has_cue?(recall_cue) ⇒ Boolean
46 47 48 |
# File 'lib/sheldon/brain.rb', line 46 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) brain_path = brain_path_for_cue(recall_cue) FileUtils.mkdir_p(brain_path) FileUtils.mv(abs_learn_path, brain_path) entry = { filepath: remove_home(abs_learn_path) } memory.add(recall_cue, entry) end |
#list_cues ⇒ Object
54 55 56 |
# File 'lib/sheldon/brain.rb', line 54 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) brain_path = brain_path_for_cue(recall_cue) FileUtils.ln_s(get_content(brain_path), destination_path, force: true) end |
#recalled?(recall_cue) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/sheldon/brain.rb', line 38 def recalled?(recall_cue) entry = memory.recall(recall_cue) destination_path = add_home(entry[:filepath]) destination_dir = File.dirname(destination_path) # Check for presence of symlink and that the symlink isn't broken File.symlink?(destination_path) && File.exists?(File.readlink(destination_path)) end |
#size ⇒ Object
50 51 52 |
# File 'lib/sheldon/brain.rb', line 50 def size memory.size end |