Class: Lowkey::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/models/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_lineObject

Returns the value of attribute end_line.



8
9
10
# File 'lib/models/source.rb', line 8

def end_line
  @end_line
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/models/source.rb', line 7

def file_path
  @file_path
end

#linesObject

Returns the value of attribute lines.



7
8
9
# File 'lib/models/source.rb', line 7

def lines
  @lines
end

#scopeObject (readonly)

Returns the value of attribute scope.



7
8
9
# File 'lib/models/source.rb', line 7

def scope
  @scope
end

#start_lineObject

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

#exportObject



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