Class: Visdiff::Revision

Inherits:
Object
  • Object
show all
Defined in:
lib/visdiff/revision.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, images = [], description = nil) ⇒ Revision

Returns a new instance of Revision.



6
7
8
9
10
# File 'lib/visdiff/revision.rb', line 6

def initialize identifier, images=[], description=nil
  @identifier = identifier
  @images = images
  @description = description
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/visdiff/revision.rb', line 4

def client
  @client
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/visdiff/revision.rb', line 3

def description
  @description
end

#identifierObject (readonly)

Returns the value of attribute identifier.



3
4
5
# File 'lib/visdiff/revision.rb', line 3

def identifier
  @identifier
end

#imagesObject (readonly)

Returns the value of attribute images.



3
4
5
# File 'lib/visdiff/revision.rb', line 3

def images
  @images
end

Instance Method Details

#add_image(identifier, filename) ⇒ Object



12
13
14
15
16
# File 'lib/visdiff/revision.rb', line 12

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

#attributesObject



33
34
35
36
37
38
39
40
# File 'lib/visdiff/revision.rb', line 33

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

#submit!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/visdiff/revision.rb', line 18

def submit!
  response = client.submit_revision(self)

  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
end