Class: Til::NoteDisplayer
- Inherits:
-
Object
- Object
- Til::NoteDisplayer
- Defined in:
- lib/til/services/note_displayer.rb
Constant Summary collapse
- HIGHLIGHT_COLORS =
{ 0 => :yellow, 1 => :light_blue, 2 => :green, 3 => :blue, 4 => :red, 5 => :magenta, 6 => :light_magenta, }
Instance Attribute Summary collapse
-
#notes ⇒ Object
Returns the value of attribute notes.
Instance Method Summary collapse
-
#initialize(notes) ⇒ NoteDisplayer
constructor
A new instance of NoteDisplayer.
- #list ⇒ Object
- #print ⇒ Object
Constructor Details
#initialize(notes) ⇒ NoteDisplayer
Returns a new instance of NoteDisplayer.
15 16 17 |
# File 'lib/til/services/note_displayer.rb', line 15 def initialize notes @notes = notes.to_note_list end |
Instance Attribute Details
#notes ⇒ Object
Returns the value of attribute notes.
3 4 5 |
# File 'lib/til/services/note_displayer.rb', line 3 def notes @notes end |
Instance Method Details
#list ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/til/services/note_displayer.rb', line 26 def list subjects_seen = Array.new longest_subject_length = notes.sort_by{|note| note.subject.length}.last.subject.length notes.each do |note| subjects_seen.push(note.subject) if !subjects_seen.include?(note.subject) color_index = subjects_seen.index(note.subject) % HIGHLIGHT_COLORS.length color = HIGHLIGHT_COLORS[color_index] spacing = " " * (longest_subject_length - note.subject.length) puts note.subject.colorize(color) + ": " + spacing + note.title.bold + " (" + note.pretty_printed_mtime + ")" end end |
#print ⇒ Object
19 20 21 22 23 24 |
# File 'lib/til/services/note_displayer.rb', line 19 def print notes.each do |note| puts note.subject.underline + ": " + note.title.bold + " (" + note.pretty_printed_mtime + ")" puts note.content end end |