Class: Mist::CodeExampleParser::Example

Inherits:
String
  • Object
show all
Defined in:
lib/mist/code_example_parser.rb

Constant Summary collapse

FILENAME_REGEXP =
/\A[\s\t\n]*file: (.*?)[\n\r]+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_offset) ⇒ Example

Returns a new instance of Example.



10
11
12
13
14
# File 'lib/mist/code_example_parser.rb', line 10

def initialize(start_offset)
  @whitespace_skipped = 0
  @start_offset = start_offset
  super()
end

Instance Attribute Details

#filenameObject



28
29
30
# File 'lib/mist/code_example_parser.rb', line 28

def filename
  @filename || explicit_filename
end

#start_offsetObject

Returns the value of attribute start_offset.



5
6
7
# File 'lib/mist/code_example_parser.rb', line 5

def start_offset
  @start_offset
end

#whitespace_skippedObject

Returns the value of attribute whitespace_skipped.



6
7
8
# File 'lib/mist/code_example_parser.rb', line 6

def whitespace_skipped
  @whitespace_skipped
end

Instance Method Details

#explicit_filenameObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mist/code_example_parser.rb', line 16

def explicit_filename
  @explicit_filename ||= if self =~ FILENAME_REGEXP
    # omit filename from self
    match = $~
    @whitespace_skipped += match.offset(0)[1] - match.offset(0)[0]
    sub! match[0], ''
    match[1]
  else
    nil
  end
end

#offsetObject



32
33
34
# File 'lib/mist/code_example_parser.rb', line 32

def offset
  start_offset...(start_offset+length+whitespace_skipped)
end