Class: Entry
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
pseudo date, yornal (obj or name).
-
#yornal ⇒ Object
readonly
pseudo date, yornal (obj or name).
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #contains?(word) ⇒ Boolean
- #delete(ask = true) ⇒ Object
- #edit(editor = editor(), action = :Modify, ignore = nil) ⇒ Object
-
#initialize(date, yornal) ⇒ Entry
constructor
A new instance of Entry.
- #matches?(regex) ⇒ Boolean
- #name ⇒ Object
- #path ⇒ Object
- #printout(delimiter = "\n\n") ⇒ Object
- #printpath(delimiter = "\n", fullpath) ⇒ Object
- #to_t ⇒ Object
Constructor Details
Instance Attribute Details
#date ⇒ Object (readonly)
pseudo date, yornal (obj or name)
3 4 5 |
# File 'lib/entry.rb', line 3 def date @date end |
#yornal ⇒ Object (readonly)
pseudo date, yornal (obj or name)
3 4 5 |
# File 'lib/entry.rb', line 3 def yornal @yornal end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
5 6 7 |
# File 'lib/entry.rb', line 5 def <=>(other) to_t <=> (other.is_a?(Entry) ? other.to_t : other) end |
#contains?(word) ⇒ Boolean
33 34 35 |
# File 'lib/entry.rb', line 33 def contains?(word) File.read(path) =~ Regexp.new(word, :i) end |
#delete(ask = true) ⇒ Object
52 53 54 55 56 |
# File 'lib/entry.rb', line 52 def delete(ask = true) pre = "You are about to delete yornal entry '#{name}'." question = "Are you sure you want to delete it?" git(:rm, "#{path}") if !ask || yes_or_no?(question, pre) end |
#edit(editor = editor(), action = :Modify, ignore = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/entry.rb', line 43 def edit(editor = editor(), action = :Modify, ignore = nil) digest = SHA256.digest(File.read(path)) system "#{editor} #{path}" return if ignore || digest == SHA256.digest(File.read(path)) git(:add, path) git(:commit, "-m '#{action} #{@yornal.name} entry #{@date}'") end |
#matches?(regex) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/entry.rb', line 37 def matches?(regex) File.read(path) =~ Regexp.new(regex) rescue RegexpError err "Malformed regexp" end |
#name ⇒ Object
25 26 27 |
# File 'lib/entry.rb', line 25 def name [@yornal.name, @date].jomp("/") end |
#path ⇒ Object
21 22 23 |
# File 'lib/entry.rb', line 21 def path [$yornalPath, name].jomp("/") end |
#printout(delimiter = "\n\n") ⇒ Object
58 59 60 61 |
# File 'lib/entry.rb', line 58 def printout(delimiter = "\n\n") $stdout.print File.read(path) $stdout.print delimiter end |
#printpath(delimiter = "\n", fullpath) ⇒ Object
63 64 65 66 |
# File 'lib/entry.rb', line 63 def printpath(delimiter = "\n", fullpath) $stdout.print(fullpath ? path : name) $stdout.print delimiter end |
#to_t ⇒ Object
29 30 31 |
# File 'lib/entry.rb', line 29 def to_t Time.new(*@date.split("/")) end |