Class: Rstsyn::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rstsyn.rb

Class Method Summary collapse

Class Method Details

.clean_additional(line) ⇒ Object



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

def self.clean_additional line
  return line.left_add_spaces!(@min_spaces)
end

.clean_command(line) ⇒ Object



63
64
65
66
# File 'lib/rstsyn.rb', line 63

def self.clean_command line
  command = /^(?<command>\:\w+\:)\s+(?<params>.+)/.match(line)
  return "#{command['command'].ljust(@min_spaces)}#{command['params']}"
end

.createTildeLine(length) ⇒ Object



51
52
53
54
55
# File 'lib/rstsyn.rb', line 51

def self.createTildeLine length
  line = ''
  length.times {line += '~'}
  return line
end

.isAdditionalParameter?(line) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/rstsyn.rb', line 72

def self.isAdditionalParameter? line
  return (/^\s+./ =~ line)
end

.isCommandwithParameters?(line) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.isCommandwithParameters? line
  return (/^\:\w+\:\s+./ =~ line)
end

.isTildeLine?(line) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rstsyn.rb', line 76

def self.isTildeLine? line
  return (/^~~/ =~ line)
end

.start(file_contents) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rstsyn.rb', line 20

def self.start file_contents
  converted_file = Array.new
  potentional_heading = ''

  file_contents.each do |line|
    line.gsub!(/\t/, '   ')

    if (!potentional_heading.empty?)
      converted_file << potentional_heading

      if self.isTildeLine? line
        line = self.createTildeLine(potentional_heading.strip.length)
      end
    end

    potentional_heading = ''
    if self.isCommandwithParameters? line # :command:      Parameters
      converted_file << self.clean_command(line)
    elsif self.isAdditionalParameter? line  #                   Additional Paramaters
      converted_file << self.clean_additional(line)
    else # Everything Else
      potentional_heading = line
    end
  end

  converted_file << potentional_heading

  return converted_file
end