Class: OfIf::File
- Inherits:
-
Object
- Object
- OfIf::File
- 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
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #lines ⇒ Object
- #to_s ⇒ Object
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
#lines ⇒ Object
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_s ⇒ Object
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 |