Sha256: 5f714807107f85113f0b843f9a4bf5fba49db3d940051957b9c20983ff502826
Contents?: true
Size: 1.9 KB
Versions: 2
Compression:
Stored size: 1.9 KB
Contents
require 'picturama' module Picturama class Album def initialize(args) @folder = args[:folder] @thumbnails = "#{args[:folder]}/thumbnails" @resized = "#{args[:folder]}/resized" @info = "#{args[:folder]}/.info.yml" end def pictures(order = true) if File.directory?(@folder) list = [] filter = "#{@folder}/*.{#{Picturama::config['allowed_formats'].join(',')}}" dir_list = generate_sorting(filter) dir_list.each do |picture| list.push(Picturama::Picture.new(picture)) end unless order list.reverse! end list end end def folder File.basename(@folder) end def name if info.nil? name! else info['album']['title'] end end def name! folder.humanize end def slug name!.to_url end def count_pictures pictures.size end def has_thumbnails? File.directory?(@thumbnails) end def has_resized? File.directory?(@resized) end def has_broken_thumbnails? thumbnails_found = Dir["#{@thumbnails}/*.{#{Picturama::config['allowed_formats'].join(',')}}"].size !has_thumbnails? || thumbnails_found < count_pictures end def init_thumbnails unless has_thumbnails? FileUtils.mkdir_p "#{@thumbnails}" end end def init_resized unless has_resized? FileUtils.mkdir_p "#{@resized}" end end def info if File.exists?(@info) YAML.load_file(@info) end end def valid? has_thumbnails? && !info.nil? end protected def generate_sorting(filter) if (filter == :size) dir_list = Dir[filter].sort_by{ |filename| File.size("#{filename}") } else dir_list = Dir[filter].sort_by{ |filename| File.ctime("#{filename}") } end dir_list end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
picturama-0.0.6 | lib/picturama/album.rb |
picturama-0.0.5 | lib/picturama/album.rb |