Class: Notes::Task
- Inherits:
-
Object
- Object
- Notes::Task
- Defined in:
- lib/notes-cli/tasks.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#context ⇒ Object
Returns the value of attribute context.
-
#date ⇒ Object
Returns the value of attribute date.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_num ⇒ Object
Returns the value of attribute line_num.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Task
constructor
A new instance of Task.
- #to_json ⇒ Object
-
#to_s ⇒ Object
Return a String in a format suitable for printing to the console that includes the line number and matched flag highlighted in color.
Constructor Details
#initialize(options = {}) ⇒ Task
Returns a new instance of Task.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/notes-cli/tasks.rb', line 7 def initialize(={}) @author = [:author] @date = [:date] @sha = [:sha] @filename = [:filename] @line_num = [:line_num] @line = [:line] @flags = [:flags] @context = [:context] end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def @author end |
#context ⇒ Object
Returns the value of attribute context.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def context @context end |
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def date @date end |
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def filename @filename end |
#flags ⇒ Object
Returns the value of attribute flags.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def flags @flags end |
#line ⇒ Object
Returns the value of attribute line.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def line @line end |
#line_num ⇒ Object
Returns the value of attribute line_num.
4 5 6 |
# File 'lib/notes-cli/tasks.rb', line 4 def line_num @line_num end |
Instance Method Details
#to_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/notes-cli/tasks.rb', line 32 def to_json { filename: @filename, line_num: @line_num, line: @line, flags: @flags, context: @context, author: @author, date: @date, sha: @sha } end |
#to_s ⇒ Object
Return a String in a format suitable for printing to the console that includes the line number and matched flag highlighted in color
TODO: different colors for different flags
23 24 25 26 27 28 29 30 |
# File 'lib/notes-cli/tasks.rb', line 23 def to_s flag_regex = Regexp.new(@flags.join('|'), true) line = @line.gsub(flag_regex) do |flag| Notes.colorize('yellow', flag) end "ln #{@line_num}: #{line.strip}" end |