Sha256: 7245852ae1c1584d22a097f9768417141228db599157143eb53a40a442020217
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
module Take class Project # Takes a file with a specific extension, and converts it to # another file with a specific extension. Woop de do. class Convert def initialize(hash, &blk) raise ArgumentError, "Expected a block" unless block_given? handle_arguments(hash) @action = Actionable.new(&blk) end 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 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 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 end end end
Version data entries
5 entries across 5 versions & 1 rubygems