Class: Buf
- Inherits:
-
Thor
- Object
- Thor
- Buf
- Defined in:
- lib/buf.rb
Instance Method Summary collapse
- #echo ⇒ Object
-
#initialize(*args) ⇒ Buf
constructor
A new instance of Buf.
- #wr(note, hours) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Buf
Returns a new instance of Buf.
14 15 16 17 18 19 20 |
# File 'lib/buf.rb', line 14 def initialize(*args) super dotfile = File.('~/.bufrc') check_dotfile(dotfile) read_dotfile(dotfile) check_files end |
Instance Method Details
#echo ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/buf.rb', line 110 def echo cull now = Time.now f = File.open(@buffile, "r") count = 1 f.each do |line| date = (line.split)[-1] date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14]) time_string = [60, 60, 24].inject([date - now]) { |m, o| m.unshift(m.shift.divmod(o)).flatten } time_string = time_string[0..2].join(":") puts "#{count}. #{(line.split)[0..-2].join(" ")} #{time_string}" count+= 1 end end |
#wr(note, hours) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/buf.rb', line 97 def wr(note, hours) t = Time.now + 60 * 60 * hours.to_i File.open(@buffile, "r") do |orig| File.unlink(@buffile) File.open(@buffile, "w") do |new| new.write("#{note} #{t.strftime("%Y%m%d-%H%M%S")}") new.write("\n") new.write(orig.read) end end end |