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 = nil, images = [], description = nil) ⇒ Revision

Returns a new instance of Revision.



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

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#identifierObject

Returns the value of attribute identifier.



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

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

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#add_image(identifier, filename) ⇒ Object



14
15
16
17
18
# File 'lib/visdiff/revision.rb', line 14

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

#attributesObject



39
40
41
42
43
44
45
46
# File 'lib/visdiff/revision.rb', line 39

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

#submit!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/visdiff/revision.rb', line 20

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