Class: Respect::DocParser

Inherits:
Object
  • Object
show all
Defined in:
lib/respect/doc_parser.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DocParser) initialize

A new instance of DocParser



4
5
6
7
# File 'lib/respect/doc_parser.rb', line 4

def initialize
  @title = nil
  @description = nil
end

Instance Attribute Details

- (Object) description (readonly)

Returns the value of attribute description



34
35
36
# File 'lib/respect/doc_parser.rb', line 34

def description
  @description
end

- (Object) title (readonly)

Returns the value of attribute title



34
35
36
# File 'lib/respect/doc_parser.rb', line 34

def title
  @title
end

Instance Method Details

- (Object) parse(string)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/respect/doc_parser.rb', line 9

def parse(string)
  ss = StringScanner.new(string)
  if ss.scan_until(/\n/)
    if ss.eos?
      @title = ss.pre_match
    else
      if ss.scan(/\n+/)
        @title = ss.pre_match.chop
        unless ss.rest.empty?
          @description = ss.rest
        end
      else
        if ss.eos?
          @title = string.chop
        else
          @description = string
        end
      end
    end
  else
    @title = string
  end
  self
end