Class: Air::Parse::Stair

Inherits:
Object
  • Object
show all
Extended by:
From
Includes:
Public
Defined in:
lib/air/parse.rb

Defined Under Namespace

Modules: From, Public

Instance Attribute Summary

Attributes included from Public

#end_at, #start_at

Instance Method Summary collapse

Methods included from From

from

Methods included from Public

#leaf?, #line, #space_prefix, #stairs

Constructor Details

#initialize(lines, at: 0) ⇒ Stair

Returns a new instance of Stair.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/air/parse.rb', line 73

def initialize lines, at: 0
  @start_at, @lines = at, lines

  next_index = at + 1
  next_line = lines[next_index]

  if next_line && (next_line.space_prefix - space_prefix) == 2
    until next_line.space_prefix <= space_prefix
      stair = Stair.from lines, at: next_index
      stairs << stair

      next_index = stair.end_at + 1
      next_line = lines[next_index]
      break unless next_line
    end

    @end_at = stairs.last.end_at
  else
    @end_at = at
  end
end