Class: Noter::Viewer
Instance Attribute Summary collapse
-
#do_paging ⇒ Object
readonly
Returns the value of attribute do_paging.
Instance Method Summary collapse
- #existing_files ⇒ Object
- #filename_from_index(index) ⇒ Object
-
#initialize(options = {}) ⇒ Viewer
constructor
A new instance of Viewer.
- #show_file(filename) ⇒ Object
- #show_file_from_index(index) ⇒ Object
- #show_files ⇒ Object
- #show_first_lines(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Viewer
Returns a new instance of Viewer.
11 12 13 14 15 16 |
# File 'lib/noter/viewer.rb', line 11 def initialize( = {}) @do_paging = [:paging].nil? ? true : [:paging] @do_colors = [:colorize].nil? ? true : [:colorize] @grep_string = [:grep_string] @tail_count = [:tail_count].nil? ? false : [:tail_count].to_i end |
Instance Attribute Details
#do_paging ⇒ Object (readonly)
Returns the value of attribute do_paging.
9 10 11 |
# File 'lib/noter/viewer.rb', line 9 def do_paging @do_paging end |
Instance Method Details
#existing_files ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/noter/viewer.rb', line 18 def existing_files return @existing_files if @existing_files if @grep_string @existing_files = `grep -l #{@grep_string} #{NoteFile.dir}/*`.split("\n") else @existing_files = Dir.glob("#{NoteFile.dir}/*").sort end if @tail_count @existing_files = @existing_files.last(@tail_count) end @existing_files end |
#filename_from_index(index) ⇒ Object
43 44 45 |
# File 'lib/noter/viewer.rb', line 43 def filename_from_index(index) existing_files[index.to_i] end |
#show_file(filename) ⇒ Object
51 52 53 54 55 |
# File 'lib/noter/viewer.rb', line 51 def show_file(filename) contents = File.read(filename) page if @do_paging puts contents end |
#show_file_from_index(index) ⇒ Object
47 48 49 |
# File 'lib/noter/viewer.rb', line 47 def show_file_from_index(index) show_file(filename_from_index(index)) end |
#show_files ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/noter/viewer.rb', line 57 def show_files existing_files.each do |filename| if @do_colors puts "\n\n#{filename}".colorize(:red) else puts "\n\n#{filename}" end show_file(filename) end end |
#show_first_lines(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/noter/viewer.rb', line 32 def show_first_lines( = {}) existing_files.sort.reverse.each do |filename| file = NoteFile.new(filename) filename_string = "" if [:with_filename] filename_string = "#{filename}: " end puts "#{file.formatted_time}: #{filename_string}#{file.first_line}" end end |