Class: Moodswings::Mood

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Mood

Returns a new instance of Mood.



11
12
13
# File 'lib/moodswings/mood.rb', line 11

def initialize(filepath)
  @filepath = filepath
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



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

def filepath
  @filepath
end

Class Method Details

.open(name) ⇒ Object



7
8
9
# File 'lib/moodswings/mood.rb', line 7

def self.open(name)
  new File.expand_path("#{Storage::DB_PATH}/#{name}.mood")
end

Instance Method Details

#contentsObject



23
24
25
# File 'lib/moodswings/mood.rb', line 23

def contents
  @contents ||= file.read
end

#fileObject



19
20
21
# File 'lib/moodswings/mood.rb', line 19

def file
  @file ||= File.open File.expand_path(@filepath)
end

#loadObject



27
28
29
# File 'lib/moodswings/mood.rb', line 27

def load
  self.instance_eval(contents)
end

#nameObject



15
16
17
# File 'lib/moodswings/mood.rb', line 15

def name
  File.basename(@filepath)
end