Class: Treedent::IndentedLine

Inherits:
Struct
  • Object
show all
Defined in:
lib/treedent/indented_line.rb

Constant Summary collapse

WHITESPACE_PATTERN =
/[ \t]*/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



4
5
6
# File 'lib/treedent/indented_line.rb', line 4

def content
  @content
end

#indentationObject

Returns the value of attribute indentation

Returns:

  • (Object)

    the current value of indentation



4
5
6
# File 'lib/treedent/indented_line.rb', line 4

def indentation
  @indentation
end

Class Method Details

.from(line_string) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/treedent/indented_line.rb', line 7

def self.from(line_string)
  scanner = StringScanner.new(line_string)
  scan = scanner.scan(WHITESPACE_PATTERN)
  indentation = (scan && scan.length) || 0
  content = scanner.rest
  new(indentation, content)
end