class Bookwatch::CodeExampleReader::Snippet

Attributes

language_pattern[R]
text[R]

Public Class Methods

new(text, language_pattern) click to toggle source
# File lib/bookwatch/code_example_reader.rb, line 24
def initialize(text, language_pattern)
  @text = text
  @language_pattern = language_pattern
end

Public Instance Methods

content() click to toggle source
# File lib/bookwatch/code_example_reader.rb, line 38
def content
  lines[1..-2].join("\n").strip
end
language() click to toggle source
# File lib/bookwatch/code_example_reader.rb, line 33
def language
  language_match = lines[0].match(language_pattern)
  Array(language_match)[1]
end
valid?() click to toggle source
# File lib/bookwatch/code_example_reader.rb, line 29
def valid?
  ! text.empty?
end

Private Instance Methods

lines() click to toggle source
# File lib/bookwatch/code_example_reader.rb, line 46
def lines
  text.split("\n")
end