class Take::Project::Convert

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

Public Class Methods

new(hash, &blk) click to toggle source
# 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

Public Instance Methods

can_convert?(from, to) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

handle_arguments(hash) click to toggle source
# File lib/take/project/convert.rb, line 36
def handle_arguments(hash)
  raise ArgumentError, "Expected hash to only have size 1" \
    unless hash.to_a.size == 1

  pair = hash.to_a[0]
  @from = pair[0]
  @to = pair[1]
end