Class: Lowkey::Source
- Inherits:
-
Object
- Object
- Lowkey::Source
- Defined in:
- lib/models/source.rb
Instance Attribute Summary collapse
-
#end_line ⇒ Object
Returns the value of attribute end_line.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(file_path:, scope:, lines:, start_line:, end_line: nil) ⇒ Source
constructor
A new instance of Source.
- #wrap(prefix:, suffix:) ⇒ Object
Constructor Details
#initialize(file_path:, scope:, lines:, start_line:, end_line: nil) ⇒ Source
Returns a new instance of Source.
10 11 12 13 14 15 16 17 |
# File 'lib/models/source.rb', line 10 def initialize(file_path:, scope:, lines:, start_line:, end_line: nil) @file_path = file_path @scope = scope @start_line = start_line @end_line = end_line @lines = lines end |
Instance Attribute Details
#end_line ⇒ Object
Returns the value of attribute end_line.
8 9 10 |
# File 'lib/models/source.rb', line 8 def end_line @end_line end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/models/source.rb', line 7 def file_path @file_path end |
#lines ⇒ Object
Returns the value of attribute lines.
7 8 9 |
# File 'lib/models/source.rb', line 7 def lines @lines end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/models/source.rb', line 7 def scope @scope end |
#start_line ⇒ Object
Returns the value of attribute start_line.
8 9 10 |
# File 'lib/models/source.rb', line 8 def start_line @start_line end |
Instance Method Details
#export ⇒ Object
37 38 39 |
# File 'lib/models/source.rb', line 37 def export lines[start_index..end_index].join end |
#wrap(prefix:, suffix:) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/models/source.rb', line 29 def wrap(prefix:, suffix:) start_line = lines[start_index] indent = start_line[/^\s+/] lines[start_index] = indent + prefix.to_s + start_line.lstrip lines[end_index] = lines[end_index] + suffix.to_s end |