Class: Decode::Comment::Tags
- Inherits:
-
Object
- Object
- Decode::Comment::Tags
- Defined in:
- lib/decode/comment/tags.rb
Constant Summary collapse
- PATTERN =
/\A\s*@(?<directive>.*?)(\s+(?<remainder>.*?))?\Z/
Class Method Summary collapse
Instance Method Summary collapse
- #ignore(lines, level = 0) ⇒ Object
-
#initialize(directives) ⇒ Tags
constructor
A new instance of Tags.
- #parse(lines, level = 0, &block) ⇒ Object
- #valid_indentation?(line, level) ⇒ Boolean
Constructor Details
#initialize(directives) ⇒ Tags
Returns a new instance of Tags.
19 20 21 |
# File 'lib/decode/comment/tags.rb', line 19 def initialize(directives) @directives = directives end |
Class Method Details
.build {|directives| ... } ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/decode/comment/tags.rb', line 11 def self.build directives = Hash.new yield directives return self.new(directives) end |
Instance Method Details
#ignore(lines, level = 0) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/decode/comment/tags.rb', line 55 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, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/decode/comment/tags.rb', line 29 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) end end end |
#valid_indentation?(line, level) ⇒ Boolean
23 24 25 |
# File 'lib/decode/comment/tags.rb', line 23 def valid_indentation?(line, level) line.start_with?(' ' * level) || line.start_with?("\t" * level) end |