Class: ThemeCheck::Corrector

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/corrector.rb

Instance Method Summary collapse

Constructor Details

#initialize(template:) ⇒ Corrector

Returns a new instance of Corrector.



5
6
7
# File 'lib/theme_check/corrector.rb', line 5

def initialize(template:)
  @template = template
end

Instance Method Details

#insert_after(node, content) ⇒ Object



9
10
11
12
# File 'lib/theme_check/corrector.rb', line 9

def insert_after(node, content)
  line = @template.full_line(node.line_number)
  line.insert(node.range[1] + 1, content)
end

#insert_before(node, content) ⇒ Object



14
15
16
17
# File 'lib/theme_check/corrector.rb', line 14

def insert_before(node, content)
  line = @template.full_line(node.line_number)
  line.insert(node.range[0], content)
end

#replace(node, content) ⇒ Object



19
20
21
22
23
# File 'lib/theme_check/corrector.rb', line 19

def replace(node, content)
  line = @template.full_line(node.line_number)
  line[node.range[0]..node.range[1]] = content
  node.markup = content
end

#wrap(node, insert_before, insert_after) ⇒ Object



25
26
27
28
29
# File 'lib/theme_check/corrector.rb', line 25

def wrap(node, insert_before, insert_after)
  line = @template.full_line(node.line_number)
  line.insert(node.range[0], insert_before)
  line.insert(node.range[1] + 1 + insert_before.length, insert_after)
end