Class: Markita::Preprocess::IterationVariables

Inherits:
Struct
  • Object
show all
Defined in:
lib/markita/preprocess.rb

Overview

State variables that change as lines are read

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#capturesObject

Returns the value of attribute captures

Returns:

  • (Object)

    the current value of captures



9
10
11
# File 'lib/markita/preprocess.rb', line 9

def captures
  @captures
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



9
10
11
# File 'lib/markita/preprocess.rb', line 9

def line
  @line
end

#rgxObject

Returns the value of attribute rgx

Returns:

  • (Object)

    the current value of rgx



9
10
11
# File 'lib/markita/preprocess.rb', line 9

def rgx
  @rgx
end

#templateObject

Returns the value of attribute template

Returns:

  • (Object)

    the current value of template



9
10
11
# File 'lib/markita/preprocess.rb', line 9

def template
  @template
end

Instance Method Details

#line2capturesObject



22
23
24
25
26
27
28
# File 'lib/markita/preprocess.rb', line 22

def line2captures
  if (mdt = rgx.match(line))
    self.captures = mdt.named_captures
  else
    self.rgx = self.template = nil
  end
end

#line2rgxObject



10
11
12
13
14
# File 'lib/markita/preprocess.rb', line 10

def line2rgx
  if (mdt = %r{^! regx = /(.*)/$}.match(line))
    self.rgx = Regexp.new(mdt[1])
  end
end

#line2templateObject



16
17
18
19
20
# File 'lib/markita/preprocess.rb', line 16

def line2template
  if (mdt = /^! template = "(.*)"$/.match(line))
    self.template = "#{mdt[1]}\n"
  end
end

#next?(line) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/markita/preprocess.rb', line 30

def next?(line)
  self.line = line
  return true if line2rgx || line2template

  line2captures if rgx
  false
end

#to_sObject



38
39
40
41
42
# File 'lib/markita/preprocess.rb', line 38

def to_s
  return (template || line).template(captures) if captures

  line
end