Module: NanDoc::SpecDoc::Ruby2RubyStandin

Included in:
Filters::Fence::Terminal, Playback::Ruby
Defined in:
lib/nandoc/spec-doc/ruby2ruby-standin.rb

Instance Method Summary collapse

Instance Method Details

#leading_indent(str) ⇒ Object



3
4
5
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 3

def leading_indent str
  /\A([ \t]*)/ =~ str && $1
end

#re_for_here(here) ⇒ Object



11
12
13
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 11

def re_for_here here
  /\A[ \t]*#{Regexp.escape(here)}[ \t]*\n?\Z/
end

#re_for_line_with_same_indent_as(str) ⇒ Object



6
7
8
9
10
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 6

def re_for_line_with_same_indent_as str
  ind = leading_indent(str)
  re = /\A#{Regexp.escape(ind)}(?=[^ \t])/
  re
end

#re_for_unindent_gsub(indent) ⇒ Object



14
15
16
17
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 14

def re_for_unindent_gsub indent
  re = /\A#{Regexp.escape(indent)}/
  re
end

#reindent_content(raw_content, indent) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 18

def reindent_content raw_content, indent
  return raw_content if indent == ''
  # of all non-blank lines find the minimum indent.
  x = raw_content.scan(/^[[:space:]]+(?=[^[:space:]])/).map(&:length).min
  # if for some reason the content has less indent than the fences,
  # don't alter any of it.
  return raw_content if x < indent.length
  re = /^#{Regexp.new(indent)}/
  unindented_content = raw_content.gsub(re, '')
  unindented_content
end

#string_diff_assert(long, short) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/nandoc/spec-doc/ruby2ruby-standin.rb', line 29

def string_diff_assert long, short
  idx = long.index(short) or fail("short not found in long -- "<<
  "#{short.inspect} in #{long.inspect}")
  head = long[0,idx] # usu. ''
  tail = long[idx + short.length..-1]
  head + tail
end