Class: RemLint::Invocation

Inherits:
Object
  • Object
show all
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, -c and the a/+/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

Class Method Summary collapse

Instance Method Summary collapse

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

#argumentsObject (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

Returns:

  • (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


54
55
56
# File 'lib/remlint/invocation.rb', line 54

def carries_info?
  arguments.any? { |argument| argument.match?(/\A-p{2,}/) }
end

#declared?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/remlint/invocation.rb', line 39

def declared?
  !arguments.empty?
end

#simple_calendar?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/remlint/invocation.rb', line 58

def simple_calendar?
  arguments.any? { |argument| argument.match?(/\A-p/) }
end

#sort_specObject

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