Class: OfIf::File

Inherits:
Object
  • Object
show all
Defined in:
lib/of_if/file.rb

Overview

Read a source file and provide each line with indentation and content length.

Defined Under Namespace

Classes: Line

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.



15
# File 'lib/of_if/file.rb', line 15

def initialize(path) = @path = path

Instance Method Details

#linesObject



17
18
19
# File 'lib/of_if/file.rb', line 17

def lines
  @lines ||= ::File.readlines(@path).map { |line| Line.new(line.rstrip) }
end

#to_sObject



21
22
23
24
25
# File 'lib/of_if/file.rb', line 21

def to_s
  lines.map do |line|
    "#{' ' * line.indent_length}#{'' * line.content_length}"
  end.join "\n"
end