Class: Logbook::Book
- Inherits:
-
Object
- Object
- Logbook::Book
- Defined in:
- lib/logbook/book.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #add(time, text) ⇒ Object
- #add_temporal(text) ⇒ Object
- #all ⇒ Object
- #create(covertext = nil) ⇒ Object
- #destroy ⇒ Object
- #get(time) ⇒ Object
-
#initialize(id = nil) ⇒ Book
constructor
A new instance of Book.
- #must_exist ⇒ Object
- #store_available ⇒ Object
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/logbook/book.rb', line 8 def id @id end |
#store ⇒ Object
Returns the value of attribute store.
9 10 11 |
# File 'lib/logbook/book.rb', line 9 def store @store end |
Instance Method Details
#add(time, text) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/logbook/book.rb', line 39 def add(time, text) store_available must_exist page = get(time) store.update(id, time, "#{page ? "#{page}\n" : ""}#{text}") time end |
#add_temporal(text) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/logbook/book.rb', line 24 def add_temporal(text) temporal = false time = nil if text =~ /(.+?)\s*:\s*(.*)/ time = Chronic.parse($1) text = $2 if time temporal = true if time end time ||= Time.now add time, text end |
#all ⇒ Object
56 57 58 59 60 61 |
# File 'lib/logbook/book.rb', line 56 def all store_available must_exist store.all(id) end |
#create(covertext = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/logbook/book.rb', line 17 def create(covertext=nil) store_available cover = covertext || "#{ENV['USER'] || 'Captain'}'s log." @id = store.create cover end |
#destroy ⇒ Object
63 64 65 66 67 68 |
# File 'lib/logbook/book.rb', line 63 def destroy store_available must_exist store.destroy(id) end |
#get(time) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/logbook/book.rb', line 48 def get(time) store_available must_exist page = store.get(id, time) end |
#must_exist ⇒ Object
74 75 76 |
# File 'lib/logbook/book.rb', line 74 def must_exist raise "create a book first" unless @id end |
#store_available ⇒ Object
70 71 72 |
# File 'lib/logbook/book.rb', line 70 def store_available raise store.error unless store.valid? end |