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

Returns a new instance of Snippet.



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

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

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



55
56
57
# File 'lib/jekyll/include_snippet/extractor.rb', line 55

def indent
  @indent
end

#linesObject (readonly)

Returns the value of attribute lines.



55
56
57
# File 'lib/jekyll/include_snippet/extractor.rb', line 55

def lines
  @lines
end

#nameObject (readonly)

Returns the value of attribute name.



55
56
57
# File 'lib/jekyll/include_snippet/extractor.rb', line 55

def name
  @name
end

Instance Method Details

#dedent(line) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/jekyll/include_snippet/extractor.rb', line 70

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

#dedented_textObject



63
64
65
66
67
68
# File 'lib/jekyll/include_snippet/extractor.rb', line 63

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