class Photo

Clase para las fotos de la fototeca

Attributes

dir_path[RW]

Para poder validar que al importar las fotos ponen un directorio sin espacios ni tildes

Public Instance Methods

aspect() click to toggle source

The aspect ratio of the dimensions.

# File app/models/photo.rb, line 130
def aspect
  width.to_f / height.to_f if !(width.blank? && height.blank?)
end
body() click to toggle source

Para poder reusar /documents/_share

# File app/models/photo.rb, line 86
def body
  ""
end
date() click to toggle source
# File app/models/photo.rb, line 49
def date
  date_time_original || created_at
end
draft()
Alias for: draft?
draft?() click to toggle source
# File app/models/photo.rb, line 80
def draft?
  !published?
end
Also aliased as: draft
geometry_from_file() click to toggle source

Should try to use Paperclip::Geometry instead returns [width, height], if possible

# File app/models/photo.rb, line 92
def geometry_from_file
  file = Photo::PHOTOS_PATH + version(:original, :relative)
  geometry = begin
               Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"])
             rescue => err
               logger.info "No he podido coger las dimensiones de #{self.id}: #{err}"
               ""
             end
  if match = (geometry.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/))
    match.to_a[1,2]
  else
    logger.info "No he podido coger las dimensiones de #{self.id}: #{geometry}"
    ""
  end
  # parse(geometry) ||
  #   raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
end
horizontal?() click to toggle source

True if the dimensions represent a horizontal rectangle

# File app/models/photo.rb, line 116
def horizontal?
  height < width if !(width.blank? && height.blank?)
end
is_public?() click to toggle source
# File app/models/photo.rb, line 70
def is_public?
  true
end
orientation() click to toggle source
# File app/models/photo.rb, line 125
def orientation
  self.vertical? ? 'portrait' : 'landscape'
end
published?() click to toggle source

Indica si la foto está publicada. Lo está si está en algún album publicado

# File app/models/photo.rb, line 75
def published?
  albums = self.albums
  albums.length > 0 && albums.collect(&:draft).include?(false)
end
set_geometry() click to toggle source
# File app/models/photo.rb, line 135
def set_geometry
  self.width, self.height = self.geometry_from_file
end
square?() click to toggle source

True if the dimensions represent a square

# File app/models/photo.rb, line 111
def square?
  height == width  if !(width.blank? && height.blank?)
end
version(size=:n70, path=:absolute) click to toggle source

Devuelve la versión de tamaño size de la foto actual.

Parámetros

  • size: tamaño deseado. Los valores permitidos son los keys de Tools::Multimedia::PHOTOS_SIZES, definido en el módulo #PhotoPaths

  • path: no se usa

# File app/models/photo.rb, line 57
def version(size=:n70, path=:absolute)
  if Tools::Multimedia::PHOTOS_SIZES.keys.include?(size)
    version_path = "#{File.dirname(self.file_path)}/#{size}/#{File.basename(self.file_path)}"
  else
    version_path = self.file_path
  end
  if path.eql?(:absolute)
    return Photo::PHOTOS_URL + version_path
  else
    return version_path
  end
end
vertical?() click to toggle source

True if the dimensions represent a vertical rectangle

# File app/models/photo.rb, line 121
def vertical?
  height > width if !(width.blank? && height.blank?)
end