Class: Jekyll::IncludeSnippet::Extractor::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/include_snippet/extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, indent:) ⇒ Snippet



43
44
45
46
47
# File 'lib/jekyll/include_snippet/extractor.rb', line 43

def initialize(name:, indent:)
  @name = name
  @indent = indent
  @lines = []
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



41
42
43
# File 'lib/jekyll/include_snippet/extractor.rb', line 41

def indent
  @indent
end

#linesObject (readonly)

Returns the value of attribute lines.



41
42
43
# File 'lib/jekyll/include_snippet/extractor.rb', line 41

def lines
  @lines
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/jekyll/include_snippet/extractor.rb', line 41

def name
  @name
end

Instance Method Details

#dedent(line) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/jekyll/include_snippet/extractor.rb', line 56

def dedent(line)
  if line.length >= indent
    line[indent..-1]
  else
    line
  end
end

#dedented_textObject



49
50
51
52
53
54
# File 'lib/jekyll/include_snippet/extractor.rb', line 49

def dedented_text
  lines
    .map { |line| dedent(line) }
    .join
    .rstrip
end