Last active
August 29, 2015 13:56
-
-
Save miyucy/9128894 to your computer and use it in GitHub Desktop.
faking markdown sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
module Faker | |
class Markdown < Lorem | |
class << self | |
def sentence(*args) | |
super[0..-2] | |
.gsub(/[^ ]+/) { |m| modify m } | |
.sub(/\A /, '') | |
.sub(/ \z/, '') + '.' | |
end | |
def h1 | |
'# ' << sentence | |
end | |
def h2 | |
'## ' << sentence | |
end | |
def h3 | |
'### ' << sentence | |
end | |
def indent(str) | |
str.each_line.map { |s| ' ' << s }.join | |
end | |
def deindent(str) | |
str.each_line.map { |s| s.sub(/\A /, '') }.join | |
end | |
def quote(str) | |
str.each_line.map { |s| '> ' << s }.join | |
end | |
def unquote(str) | |
str.each_line.map { |s| s.sub(/\A> ?/, '') }.join | |
end | |
def numbered_list(num = 3) | |
num.times.map { |i| " #{i + 1}. " << sentence }.join("\n") | |
end | |
def list(num = 3) | |
num.times.map { ' * ' << sentence }.join("\n") | |
end | |
def lists(num = 3) | |
num.times.map { list num } | |
end | |
def normal(word) | |
word | |
end | |
def italic(word) | |
'*' << word << '*' | |
end | |
def bold(word) | |
italic italic word | |
end | |
def monospace(word) | |
'`' << word << '`' | |
end | |
MODIFIERS = %i(normal normal normal normal normal normal normal italic bold monospace) | |
def modify(word) | |
method(MODIFIERS.sample).call(word) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment