lib/crossyglot/puzzle.rb
# Convert to a different format subclass.
#
# @param [Class, string] The class name of file extension of the format to conver to.
# @returns [Puzzle] A new puzzle object of the appropriate class, or this puzzle object if the
#                   class is the same. Raises an InvalidPuzzleFormat if given something bogus.
Convert to a different format subclass.
Convert to a different format subclass .
def convert_to(format)
      clazz = FORMAT_EXTENSIONS[format.to_s] || format
      raise InvalidPuzzleFormat.new  unless FORMAT_EXTENSIONS.values.include?(clazz)
      if kind_of?(clazz)
        self
      else
        new_puzzle = clazz.new
        ATTRIBUTES.each do |attr|
          new_puzzle.public_send("#{attr}=", public_send(attr))
        end
        new_puzzle.cells.concat(cells.map(&:clone))
        new_puzzle
      end
    end
def convert_to ( format ) clazz = FORMAT_EXTENSIONS [ format . to_s ] || format raise InvalidPuzzleFormat . new unless FORMAT_EXTENSIONS . values . include? ( clazz ) if kind_of? ( clazz ) self else new_puzzle = clazz . new ATTRIBUTES . each do | attr | new_puzzle . public_send ( "#{attr}=" , public_send ( attr ) ) end new_puzzle . cells . concat ( cells . map ( & :clone ) ) new_puzzle end end
Convert to a different format subclass.
Convert to a different format subclass .
[Puzzle] A new puzzle object of the appropriate class, or this puzzle object if the class is the same. Raises an InvalidPuzzleFormat if given something bogus.
[ Puzzle ] A new puzzle object of the appropriate class or this puzzle object if the class is the same . Raises an InvalidPuzzleFormat if given something bogus .
format
The class name of file extension of the format to conver to.
The class name of file extension of the format to conver to .