Class: Renamr::RemoveAction

Inherits:
Action
  • Object
show all
Defined in:
lib/renamr/remove.rb

Overview

Removes symbols between left and right positions.

Instance Method Summary collapse

Methods inherited from Action

#p2m, #set

Constructor Details

#initialize(pos, len) ⇒ RemoveAction

Returns a new instance of RemoveAction.



11
12
13
14
15
16
17
18
# File 'lib/renamr/remove.rb', line 11

def initialize(pos, len)
  raise 'len cannot bi nil.' if len.nil?
  raise 'pos cannot be nil.' if pos.nil?
  raise 'pos has to be positive.' unless pos.to_i.positive?

  @pos = pos.to_i
  @len = len.to_i
end

Instance Method Details

#do(src) ⇒ Object



20
21
22
23
24
# File 'lib/renamr/remove.rb', line 20

def do(src)
  return src[@len..-1] if @pos == 1

  src[0..@pos - 1] + src[@pos + @len..-1]
end