class Decode::Comment::Tags
Constants
- PATTERN
Public Class Methods
build() { |directives| ... }
click to toggle source
# File lib/decode/comment/tags.rb, line 26 def self.build directives = Hash.new yield directives return self.new(directives) end
new(directives)
click to toggle source
# File lib/decode/comment/tags.rb, line 34 def initialize(directives) @directives = directives end
Public Instance Methods
ignore(lines, level = 0)
click to toggle source
# File lib/decode/comment/tags.rb, line 70 def ignore(lines, level = 0) if line = lines.first # Is it at the right indentation level: return unless valid_indentation?(line, level) lines.shift end end
parse(lines, level = 0) { |parse( match, match, lines, self, level| ... }
click to toggle source
# File lib/decode/comment/tags.rb, line 44 def parse(lines, level = 0, &block) while line = lines.first # Is it at the right indentation level: return unless valid_indentation?(line, level) # We are going to consume the line: lines.shift # Match it against a tag: if match = PATTERN.match(line) if klass = @directives[match[:directive]] yield klass.parse( match[:directive], match[:remainder], lines, self, level ) else # Ignore unknown directive. end # Or it's just text: else yield Text.new(line.strip) end end end
valid_indentation?(line, level)
click to toggle source
# File lib/decode/comment/tags.rb, line 38 def valid_indentation?(line, level) line.start_with?(' ' * level) || line.start_with?("\t" * level) end