I have a series of string manipulation, I realize this with the following code. I want it to be more elegant and readable such as str.sub_heading().sub_codeblock()...
, how could I rewrite my code?
def sub_heading(str)
str.gsub!(/^(#+)\w+/) {|m| m.gsub("#", "=")}
str.gsub!(/^(=+)(.+)/, '\1 \2 \1')
end
def sub_codeblock(str)
str.gsub!(/```(.+\n)((.|\n)+)```/, '{{{#!text_pygments \1\2}}}')
end
def sub_inlinecode(str)
str.gsub!(/`(.+)`/, '{{{\1}}}')
end
def sub_bold(str)
str.gsub!(/([^\w]|^)\*\*\w[\w\s\d\-_'"]*\*\*([^\w]|$)/) {|m| m.gsub("**", "'''")}
end
def sub_italic(str)
str.gsub!(/([^*]|^)\*\w[\w\s\d\-_'"]*\*([^*]|$)/) {|m| m.gsub("*", "''")}
end
def sub_link(str)
str.gsub!(/\[\[(.+)\|(.+)\]\]/, '[[\2|\1]]')
end
sub_heading(inputdata)
sub_codeblock(inputdata)
sub_inlinecode(inputdata)
sub_bold(inputdata)
sub_italic(inputdata)
sub_link(inputdata)