Class: Notes::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/notes-cli/tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @author   = options[:author]
  @date     = options[:date]
  @sha      = options[:sha]
  @filename = options[:filename]
  @line_num = options[:line_num]
  @line     = options[:line]
  @flags    = options[:flags]
  @context  = options[:context]
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def author
  @author
end

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def context
  @context
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def date
  @date
end

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def filename
  @filename
end

#flagsObject

Returns the value of attribute flags.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def flags
  @flags
end

#lineObject

Returns the value of attribute line.



4
5
6
# File 'lib/notes-cli/tasks.rb', line 4

def line
  @line
end

#line_numObject

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_jsonObject



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_sObject

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