Sha256: 2208c29aec470bbabc525791a70138647bc4d92765afe2cda30ec04d7bea28f2

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module Visdiff
  class Revision
    attr_reader :images, :url, :id
    attr_accessor :identifier, :description
    attr_accessor :client

    def initialize(identifier=nil, images=[], description=nil)
      @identifier = identifier
      @images = images
      @description = description
      @url = @id = nil
    end

    def add_image identifier, filename
      image = Image.new(identifier, filename)
      image.client = client
      @images << image
    end

    def submit!
      response = client.submit_revision(self)
      @id = response['id']
      @url = response['url']

      missing_images = []
      response['images'].each do |rimg|
        missing_images << rimg['signature'] unless rimg['url']
      end
      puts "Uploading #{missing_images.length} new images (#{response['images'].length} total)"

      images.each do |image|
        next unless missing_images.include?(image.signature)
        client.submit_image(image)
      end

      puts @url
    end

    def attributes
      {
        identifier: identifier,
        image_attributes: images.map do |image|
          {identifier: image.identifier, description: description, signature: image.signature}
        end
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
visdiff-0.0.7 lib/visdiff/revision.rb
visdiff-0.0.6 lib/visdiff/revision.rb
visdiff-0.0.5 lib/visdiff/revision.rb