Class: GallerySync::FileGallery

Inherits:
Gallery
  • Object
show all
Defined in:
lib/gallery_sync/gallery_sync.rb

Instance Method Summary collapse

Methods inherited from Gallery

#[], #albums, #serialized_albums, #sync_to

Constructor Details

#initialize(name, root_path) ⇒ FileGallery



78
79
80
81
# File 'lib/gallery_sync/gallery_sync.rb', line 78

def initialize(name, root_path)
  @root_path = root_path
  @name = name
end

Instance Method Details

#load_albumsObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gallery_sync/gallery_sync.rb', line 83

def load_albums
  albums = []
  album_dirs = Dir.glob(File.join(@root_path,'*',''))
  album_dirs.each { |album_dir|
    album = Album.new(File.basename(album_dir))
     = File.join(album_dir, "album.yml")
    album.(File.open()) if File.exist?()
    photos = Dir.glob(File.join(album_dir, "*.{png,jpg}")).select { |f| File.file?(f)}.map { |f|
      FilePhoto.new(album,File.basename(f),f)
    }
    if !photos.empty?
      albums << album
      album.photos = photos
      album.album_photo = photos[0]
    end
  }
  albums
end

#rm_album(album_name) ⇒ Object



106
107
108
109
110
111
# File 'lib/gallery_sync/gallery_sync.rb', line 106

def rm_album album_name
  album = self[album_name]
  album.photos.each { |p|
    p.rm
  }
end

#rm_photo(photo) ⇒ Object



102
103
104
# File 'lib/gallery_sync/gallery_sync.rb', line 102

def rm_photo photo
  photo.rm    
end

#to_sObject



134
135
136
# File 'lib/gallery_sync/gallery_sync.rb', line 134

def to_s
  @root_path
end

#update_album_metadata(album, metadata) ⇒ Object



127
128
129
130
131
132
# File 'lib/gallery_sync/gallery_sync.rb', line 127

def (album,)
  file = File.join(@root_path, album.name, "album.yml")
  File.open(file, 'w') do |out| 
    YAML::dump(, out)
  end
end

#upload_album(album) ⇒ Object



115
116
117
118
119
120
# File 'lib/gallery_sync/gallery_sync.rb', line 115

def upload_album album
  Dir.mkdir File.join(@root_path, album.name)
  album.photos.each { |photo|  
    upload_photo(photo) 
  }
end

#upload_photo(photo) ⇒ Object



122
123
124
125
# File 'lib/gallery_sync/gallery_sync.rb', line 122

def upload_photo(photo)
  path = File.join(@root_path, photo.album.name, photo.name)
  File.open(path,'wb') {|io|io.write(photo.file)}
end