Class: Bookbinder::CodeExampleReader::Snippet
- Inherits:
-
Object
- Object
- Bookbinder::CodeExampleReader::Snippet
- Defined in:
- lib/bookbinder/code_example_reader.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(text, language_pattern) ⇒ Snippet
constructor
A new instance of Snippet.
- #language ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(text, language_pattern) ⇒ Snippet
Returns a new instance of Snippet.
24 25 26 27 |
# File 'lib/bookbinder/code_example_reader.rb', line 24 def initialize(text, language_pattern) @text = text @language_pattern = language_pattern end |
Instance Method Details
#content ⇒ Object
38 39 40 |
# File 'lib/bookbinder/code_example_reader.rb', line 38 def content lines[1..-2].join("\n").strip end |
#language ⇒ Object
33 34 35 36 |
# File 'lib/bookbinder/code_example_reader.rb', line 33 def language language_match = lines[0].match(language_pattern) Array(language_match)[1] end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/bookbinder/code_example_reader.rb', line 29 def valid? ! text.empty? end |