Class: RemLint::Invocation
- Inherits:
-
Object
- Object
- RemLint::Invocation
- Defined in:
- lib/remlint/invocation.rb
Overview
How a file is meant to be run, declared in the file.
Three of the checks a Remind file wants need something that is not in the
file: the command line. -g decides whether a sort happens, -p versus
-pp decides whether INFO headers reach the back-end at all, and
calendar mode versus agenda mode decides whether TODO means anything.
Rather than guess three times, the file says so once:
# remlint:invocation remind -pp -g /path/to/file
No declaration means no opinion, and the rules that depend on it stay silent. That is the honest default: a file with no declaration is one whose invocation the linter genuinely does not know.
Constant Summary collapse
- DIRECTIVE =
/[#;]\s*remlint:invocation\s+(?<command>.+?)\s*\z/- CALENDAR =
-p,-pp,-s,-cand thea/+/digit suffixes each may carry. /\A-(?<kind>[psc])(?<rest>[a-z+0-9]*)\z/- SORT =
/\A-g(?<spec>[a-z]*)\z/
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
Class Method Summary collapse
-
.of(document) ⇒ Object
Reads the first declaration in a document, or an empty one.
Instance Method Summary collapse
- #agenda? ⇒ Boolean
-
#calendar? ⇒ Boolean
Any of the calendar-producing modes.
-
#carries_info? ⇒ Boolean
-ppand above carry INFO headers to the back-end; plain-pdoes not. - #declared? ⇒ Boolean
-
#initialize(arguments) ⇒ Invocation
constructor
A new instance of Invocation.
- #simple_calendar? ⇒ Boolean
-
#sort_spec ⇒ Object
The
-gspec, or nil.
Constructor Details
#initialize(arguments) ⇒ Invocation
Returns a new instance of Invocation.
28 29 30 |
# File 'lib/remlint/invocation.rb', line 28 def initialize(arguments) @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
26 27 28 |
# File 'lib/remlint/invocation.rb', line 26 def arguments @arguments end |
Class Method Details
.of(document) ⇒ Object
Reads the first declaration in a document, or an empty one.
33 34 35 36 37 |
# File 'lib/remlint/invocation.rb', line 33 def self.of(document) declaration = document.raw_lines.filter_map { |raw| raw.match(DIRECTIVE) }.first new(declaration ? declaration[:command].split : []) end |
Instance Method Details
#agenda? ⇒ Boolean
49 50 51 |
# File 'lib/remlint/invocation.rb', line 49 def agenda? declared? && !calendar? end |
#calendar? ⇒ Boolean
Any of the calendar-producing modes. Everything else is agenda mode, which is where TODO semantics live.
45 46 47 |
# File 'lib/remlint/invocation.rb', line 45 def calendar? arguments.any? { |argument| argument.match?(CALENDAR) } end |
#carries_info? ⇒ Boolean
-pp and above carry INFO headers to the back-end; plain -p does not.
54 55 56 |
# File 'lib/remlint/invocation.rb', line 54 def carries_info? arguments.any? { |argument| argument.match?(/\A-p{2,}/) } end |
#declared? ⇒ Boolean
39 40 41 |
# File 'lib/remlint/invocation.rb', line 39 def declared? !arguments.empty? end |
#simple_calendar? ⇒ Boolean
58 59 60 |
# File 'lib/remlint/invocation.rb', line 58 def simple_calendar? arguments.any? { |argument| argument.match?(/\A-p/) } end |
#sort_spec ⇒ Object
The -g spec, or nil. Remind takes up to four characters, each a or
d, for date, time, priority and timedness.
64 65 66 67 68 |
# File 'lib/remlint/invocation.rb', line 64 def sort_spec match = arguments.filter_map { |argument| argument.match(SORT) }.first match && match[:spec] end |