Class: Bookbinder::CodeExampleReader::Snippet
- Inherits:
-
Object
- Object
- Bookbinder::CodeExampleReader::Snippet
- Defined in:
- lib/bookbinder/code_example_reader.rb
Instance Method Summary collapse
- #available? ⇒ Boolean
- #content ⇒ Object
-
#initialize(marker, working_copy) ⇒ Snippet
constructor
A new instance of Snippet.
- #language ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(marker, working_copy) ⇒ Snippet
Returns a new instance of Snippet.
28 29 30 31 |
# File 'lib/bookbinder/code_example_reader.rb', line 28 def initialize(marker, working_copy) @marker = marker @working_copy = working_copy end |
Instance Method Details
#available? ⇒ Boolean
33 34 35 |
# File 'lib/bookbinder/code_example_reader.rb', line 33 def available? working_copy.available? end |
#content ⇒ Object
47 48 49 50 |
# File 'lib/bookbinder/code_example_reader.rb', line 47 def content lines = get_snippet(marker, working_copy).split("\n") lines[1..-2].join("\n") end |
#language ⇒ Object
41 42 43 44 45 |
# File 'lib/bookbinder/code_example_reader.rb', line 41 def language lines = get_snippet(marker, working_copy).split("\n") language_match = lines[0].match(/code_snippet #{Regexp.escape(marker)} start (\w+)/) Array(language_match)[1] end |
#valid? ⇒ Boolean
37 38 39 |
# File 'lib/bookbinder/code_example_reader.rb', line 37 def valid? ! get_snippet(marker, working_copy).empty? end |