Class: NA::Action
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#note ⇒ Object
Returns the value of attribute note.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(file, project, parent, action, idx, note = []) ⇒ Action
constructor
A new instance of Action.
- #inspect ⇒ Object
-
#pretty(extension: 'taskpaper', template: {}, regexes: [], notes: false) ⇒ Object
Pretty print an action.
- #search_match?(any: [], all: [], none: []) ⇒ Boolean
- #tags_match?(any: [], all: [], none: []) ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(file, project, parent, action, idx, note = []) ⇒ Action
Returns a new instance of Action.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/na/action.rb', line 9 def initialize(file, project, parent, action, idx, note = []) super() @file = file @project = project @parent = parent @action = action.gsub(/\{/, '\\{') = @line = idx @note = note end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7 8 9 |
# File 'lib/na/action.rb', line 7 def action @action end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/na/action.rb', line 5 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/na/action.rb', line 5 def line @line end |
#note ⇒ Object
Returns the value of attribute note.
7 8 9 |
# File 'lib/na/action.rb', line 7 def note @note end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/na/action.rb', line 5 def parent @parent end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
5 6 7 |
# File 'lib/na/action.rb', line 5 def project @project end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'lib/na/action.rb', line 5 def end |
Instance Method Details
#inspect ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/na/action.rb', line 30 def inspect " @file: \#{@file}\n @project: \#{@project}\n @parent: \#{@parent.join('>')}\n @action: \#{@action}\n @note: \#{@note}\n EOINSPECT\nend\n" |
#pretty(extension: 'taskpaper', template: {}, regexes: [], notes: false) ⇒ Object
Pretty print an action
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/na/action.rb', line 50 def pretty(extension: 'taskpaper', template: {}, regexes: [], notes: false) # Default colorization, can be overridden with full or partial template variable default_template = { file: '{xbk}', parent: '{c}', parent_divider: '{xw}/', action: '{bg}', project: '{xbk}', tags: '{m}', value_parens: '{m}', values: '{y}', output: '%filename%parents| %action', note: '{dw}' } template = default_template.merge(template) # Create the hierarchical parent string parents = @parent.map do |par| NA::Color.template("#{template[:parent]}#{par}") end.join(NA::Color.template(template[:parent_divider])) parents = "{dc}[{x}#{parents}{dc}]{x} " # Create the project string project = NA::Color.template("#{template[:project]}#{@project}{x} ") # Create the source filename string, substituting ~ for HOME and removing extension file = @file.sub(%r{^\./}, '').sub(/#{ENV['HOME']}/, '~') file = file.sub(/\.#{extension}$/, '') # colorize the basename file = file.sub(/#{File.basename(@file, ".#{extension}")}$/, "{dw}#{File.basename(@file, ".#{extension}")}{x}") file_tpl = "#{template[:file]}#{file} {x}" filename = NA::Color.template(file_tpl) # Add notes if needed note = if notes && @note.count.positive? NA::Color.template("\n#{@note.map { |l| " #{template[:note]}• #{l}{x}" }.join("\n")}") else '' end # colorize the action and highlight tags action = NA::Color.template("#{template[:action]}#{@action.sub(/ @#{NA.na_tag}\b/, '')}{x}") action = action.(color: template[:tags], parens: template[:value_parens], value: template[:values], last_color: template[:action]) # Replace variables in template string and output colorized NA::Color.template(template[:output].gsub(/%filename/, filename) .gsub(/%project/, project) .gsub(/%parents?/, parents) .gsub(/%action/, action.highlight_search(regexes)) .gsub(/%note/, note)).gsub(/\\\{/, '{') end |
#search_match?(any: [], all: [], none: []) ⇒ Boolean
108 109 110 |
# File 'lib/na/action.rb', line 108 def search_match?(any: [], all: [], none: []) search_matches_any(any) && search_matches_all(all) && search_matches_none(none) end |
#tags_match?(any: [], all: [], none: []) ⇒ Boolean
104 105 106 |
# File 'lib/na/action.rb', line 104 def (any: [], all: [], none: []) tag_matches_any(any) && tag_matches_all(all) && tag_matches_none(none) end |
#to_s ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/na/action.rb', line 21 def to_s note = if @note.count.positive? "\n#{@note.join("\n")}" else '' end "(#{@file}:#{@line}) #{@project}:#{@parent.join('>')} | #{@action}#{note}" end |