Class: Bookbinder::CodeExampleReader

Inherits:
Object
  • Object
show all
Defined in:
lib/bookbinder/code_example_reader.rb

Defined Under Namespace

Classes: InvalidSnippet, Snippet

Instance Method Summary collapse

Constructor Details

#initialize(out: out) ⇒ CodeExampleReader

Returns a new instance of CodeExampleReader.



9
10
11
# File 'lib/bookbinder/code_example_reader.rb', line 9

def initialize(out: out)
  @out = out
end

Instance Method Details

#get_snippet_and_language_at(marker, working_copy) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bookbinder/code_example_reader.rb', line 13

def get_snippet_and_language_at(marker, working_copy)
  snippet = Snippet.new(marker, working_copy)
  if snippet.available? && !snippet.valid?
    raise InvalidSnippet.new(working_copy.full_name, marker)
  elsif snippet.available?
    [snippet.content, snippet.language]
  else
    out << "  skipping (not found) #{working_copy.full_name}"
    ''
  end
end