Class: GallerySync::Gallery
- Inherits:
-
Object
- Object
- GallerySync::Gallery
show all
- Defined in:
- lib/gallery_sync/gallery_sync.rb
Instance Method Summary
collapse
Instance Method Details
#[](album_name) ⇒ Object
61
62
63
64
|
# File 'lib/gallery_sync/gallery_sync.rb', line 61
def [](album_name)
r = albums.select { |a| a.name == album_name }
r.empty? ? nil : r.first
end
|
#albums(options = {}) ⇒ Object
options, :reload, to reload albums, returns a cached version otherwise.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/gallery_sync/gallery_sync.rb', line 9
def albums(options = {})
if @albums.nil? or options[:reload]
@albums = load_albums
end
@albums.sort! { |a, b|
rank_a = a.metadata.fetch('rank', 0)
rank_b = b.metadata.fetch('rank', 0)
date_a = a.metadata.fetch('date_from', Date.civil())
date_b = b.metadata.fetch('date_from', Date.civil())
if(rank_a == rank_b)
date_a <=> date_b
else
rank_a <=> rank_b
end
}.reverse!
@albums
end
|
#serialized_albums ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/gallery_sync/gallery_sync.rb', line 27
def serialized_albums
ser_albums = []
albums.each { |album|
ser_album = Album.new(album.name)
ser_album.metadata = album.metadata
ser_album.album_photo = SerPhoto::value_of(album.album_photo)
ser_album.photos = []
album.photos.each { |photo|
ser_album.photos << SerPhoto::value_of(photo)
}
ser_albums << ser_album
}
ser_albums
end
|
#sync_to(dest_gallery) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gallery_sync/gallery_sync.rb', line 42
def sync_to(dest_gallery)
src = self
src_albums = src.albums
dest_albums = dest_gallery.albums
to_be_deleted = dest_albums.map(&:name) - src_albums.map(&:name)
to_be_deleted.each { |album| dest_gallery.rm_album(album) }
src_albums.each { |album|
if(dest_gallery[album.name])
album.merge_to(dest_gallery[album.name], dest_gallery) if dest_gallery[album.name]
else
dest_gallery.upload_album(album)
dest_gallery.update_album_metadata(album,album.metadata)
end
}
end
|