Class: RemLint::Command

Inherits:
Struct
  • Object
show all
Defined in:
lib/remlint/command.rb

Overview

A classified logical line: which keyword opens it, and what follows.

keyword is nil for three different things, and rules must not confuse them, so ask rather than test for nil:

blank?    nothing but whitespace
comment?  opens with `#` or `;`
implicit? a trigger with the `REM` left off -- `1 Nov ++12 MSG ...`,
        which the manual explicitly allows and which is the ordinary
        way to write a reminder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



17
18
19
# File 'lib/remlint/command.rb', line 17

def args
  @args
end

#keywordObject

Returns the value of attribute keyword

Returns:

  • (Object)

    the current value of keyword



17
18
19
# File 'lib/remlint/command.rb', line 17

def keyword
  @keyword
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



17
18
19
# File 'lib/remlint/command.rb', line 17

def kind
  @kind
end

#logical_lineObject

Returns the value of attribute logical_line

Returns:

  • (Object)

    the current value of logical_line



17
18
19
# File 'lib/remlint/command.rb', line 17

def logical_line
  @logical_line
end

#wordObject

Returns the value of attribute word

Returns:

  • (Object)

    the current value of word



17
18
19
# File 'lib/remlint/command.rb', line 17

def word
  @word
end

Instance Method Details

#args_offsetObject

Where args begins in text. args is always a suffix of text, so a rule that found something at offset N in args can hand args_offset + N to LogicalLine#position_at and get a real file position.



28
29
30
# File 'lib/remlint/command.rb', line 28

def args_offset
  text.length - args.length
end

#blank?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/remlint/command.rb', line 44

def blank?
  kind == :blank
end

#code?Boolean

Blank lines and comments are not commands at all.

Returns:

  • (Boolean)


59
60
61
# File 'lib/remlint/command.rb', line 59

def code?
  kind == :keyword || kind == :implicit
end

#comment?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/remlint/command.rb', line 48

def comment?
  kind == :comment
end

#implicit?Boolean

A command line that opens with no recognisable keyword. Remind reads it as a bare trigger with an implicit REM.

Returns:

  • (Boolean)


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

def implicit?
  kind == :implicit
end

#keyword?(*names) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/remlint/command.rb', line 63

def keyword?(*names)
  !keyword.nil? && names.map(&:upcase).include?(keyword.name)
end

#keyword_columnObject

The column, 1-based, where the keyword itself starts.



68
69
70
# File 'lib/remlint/command.rb', line 68

def keyword_column
  (text.index(/\S/) || 0) + 1
end

#last_lineObject



36
37
38
# File 'lib/remlint/command.rb', line 36

def last_line
  logical_line.last_line
end

#lineObject



32
33
34
# File 'lib/remlint/command.rb', line 32

def line
  logical_line.line
end

#textObject



40
41
42
# File 'lib/remlint/command.rb', line 40

def text
  logical_line.text
end