Class: SvnTransform::Transform::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/svn-transform/transform/extension.rb

Overview

Convert file extensions

Instance Method Summary collapse

Constructor Details

#initialize(file, extensions) ⇒ Extension

Initialize Extension Transform.

Parameters

file<SvnTransform::File>

File at a given revision

extensions<~each_pair>

A Hash of old => new extension

Example

SvnTransform::Transform::Extension.new(@file,
  {:txt => :markdown, :ruby => :rb}
)


17
18
19
20
21
22
23
# File 'lib/svn-transform/transform/extension.rb', line 17

def initialize(file, extensions)
  @file = file
  @extensions = {}
  (extensions || {}).each_pair do |existing, change_to|
    @extensions[".#{existing}"] = ".#{change_to}"
  end
end

Instance Method Details

#runObject

Check if this @file has one of the extensions (matches a key). If so, change its extension.

Returns

True, False

indicating whether a change was made.



30
31
32
33
34
35
36
37
38
# File 'lib/svn-transform/transform/extension.rb', line 30

def run
  @extensions.each_pair do |existing, change_to|
    if @file.path.extname == existing
      @file.basename = @file.basename.gsub(/#{existing}\Z/, change_to)
      return true
    end
  end
  return false
end