class Rstsyn::Parser
Public Class Methods
clean_additional(line)
click to toggle source
# File lib/rstsyn.rb, line 58 def self.clean_additional line return line.left_add_spaces!(@min_spaces) end
clean_command(line)
click to toggle source
# 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)
click to toggle source
# File lib/rstsyn.rb, line 51 def self.createTildeLine length line = '' length.times {line += '~'} return line end
isAdditionalParameter?(line)
click to toggle source
# File lib/rstsyn.rb, line 72 def self.isAdditionalParameter? line return (/^\s+./ =~ line) end
isCommandwithParameters?(line)
click to toggle source
# File lib/rstsyn.rb, line 68 def self.isCommandwithParameters? line return (/^\:\w+\:\s+./ =~ line) end
isTildeLine?(line)
click to toggle source
# File lib/rstsyn.rb, line 76 def self.isTildeLine? line return (/^~~/ =~ line) end
start(file_contents)
click to toggle source
# 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