Class: Take::Project::Convert

Inherits:
Object
  • Object
show all
Defined in:
lib/take/project/convert.rb

Overview

Takes a file with a specific extension, and converts it to another file with a specific extension. Woop de do.

Instance Method Summary collapse

Constructor Details

#initialize(hash, &blk) ⇒ Convert

Returns a new instance of Convert.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/take/project/convert.rb', line 8

def initialize(hash, &blk)
  raise ArgumentError, "Expected a block" unless block_given?
  handle_arguments(hash)
  @action = Actionable.new(&blk)
end

Instance Method Details

#can_convert?(from, to) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/take/project/convert.rb', line 14

def can_convert?(from, to)
  from_ext, to_ext = [from, to].map do |file|
    if file.respond_to?(:extname)
      file.extname
    else
      ::File.extname(file)
    end
  end

  @from == from_ext && @to == to_ext
end

#convert(project, from, to) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
# File 'lib/take/project/convert.rb', line 26

def convert(project, from, to)
  raise ArgumentError, "Cannot convert #{from.inspect} to " \
    "#{to.inspect} with this converter!" \
    unless can_convert?(from, to)

  @action.call(project, :input => from, :output => to)
end