Class: Renamr::RemoveAction
Overview
Removes a substring by 1-based position and length.
Instance Method Summary collapse
- #do(src) ⇒ Object
-
#initialize(pos, len) ⇒ RemoveAction
constructor
A new instance of RemoveAction.
Methods inherited from Action
Constructor Details
#initialize(pos, len) ⇒ RemoveAction
Returns a new instance of RemoveAction.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/renamr/remove.rb', line 12 def initialize(pos, len) super() raise 'len cannot be nil.' if len.nil? raise 'len must be positive.' unless len.to_i.positive? raise 'pos cannot be nil.' if pos.nil? raise 'pos must be positive.' unless pos.to_i.positive? @pos = pos.to_i @len = len.to_i end |
Instance Method Details
#do(src) ⇒ Object
23 24 25 |
# File 'lib/renamr/remove.rb', line 23 def do(src) src[0...(@pos - 1)] + (src[(@pos - 1 + @len)..] || '') end |