class Script2md::Convert

Attributes

language_type[R]
text[RW]

Public Class Methods

new(text, language_type: nil) click to toggle source
# File lib/script2md.rb, line 14
def initialize(text, language_type: nil)
  @text = text
  @language_type = language_type
end

Public Instance Methods

convert() click to toggle source
# File lib/script2md.rb, line 21
def convert
  remove_shebang!
  code_into_codeblock!
  headling_comment_to_plaintext!
  format!
  self
end

Private Instance Methods

code_into_codeblock!() click to toggle source
# File lib/script2md.rb, line 37
def code_into_codeblock!
  text.gsub!(/(^(?!#).+$\n?)((^(?!#).*$\n?)*(^(?!#).+$))?/, "```#{language_type}\n\\0\n```")
end
format!() click to toggle source
# File lib/script2md.rb, line 46
def format!
  text.gsub!(/\A[\n\r]+|[\n\r]+\z/, '')
end
headling_comment_to_plaintext!() click to toggle source
# File lib/script2md.rb, line 41
def headling_comment_to_plaintext!
  text.gsub!(/^#\s+?$/, "")
  text.gsub!(/^#\s+?([^\n\r]+)$/, "\\1")
end
remove_shebang!() click to toggle source
# File lib/script2md.rb, line 33
def remove_shebang!
  text.gsub!(/^#!.+/, '') 
end