Class: Sticky::Note

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, tag, db, timestamp = Time.now) ⇒ Note

Returns a new instance of Note.



23
24
25
26
27
28
# File 'lib/sticky/note.rb', line 23

def initialize(message, tag, db, timestamp = Time.now)
  @message = message
  @db = db
  @tag = tag
  @timestamp = timestamp
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



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

def db
  @db
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#tagObject

Returns the value of attribute tag.



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

def tag
  @tag
end

#timestampObject

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

Class Method Details

.build(message, tag = nil, db = Sticky::Store.new) ⇒ Object



8
9
10
# File 'lib/sticky/note.rb', line 8

def build(message, tag = nil, db = Sticky::Store.new)
  new(message, tag, db)
end

.delete!(tag, db = Sticky::Store.new) ⇒ Object



18
19
20
# File 'lib/sticky/note.rb', line 18

def delete!(tag, db = Sticky::Store.new)
  db.delete!(tag)
end

.show(tag, date, db = Sticky::Store.new) ⇒ Object



12
13
14
15
16
# File 'lib/sticky/note.rb', line 12

def show(tag, date, db = Sticky::Store.new)
  db.fetch(tag, date) do |note|
    puts "#{note.timestamp} #{note.message}"
  end
end

Instance Method Details

#save!Object



30
31
32
# File 'lib/sticky/note.rb', line 30

def save!
  db.save!(self)
end

#to_yaml_propertiesObject



34
35
36
# File 'lib/sticky/note.rb', line 34

def to_yaml_properties
  [:@message, :@tag, :@timestamp]
end