Class Photo
In: app/models/photo.rb
Parent: ActiveRecord::Base

Clase para las fotos de la fototeca

Methods

Included Modules

PhotoPaths FerretMethods

External Aliases

tags_for_ferret -> tags_for_ferret_orig

Attributes

dir_path  [RW]  Para poder validar que al importar las fotos ponen un directorio sin espacios ni tildes

Public Instance methods

The aspect ratio of the dimensions.

[Source]

     # File app/models/photo.rb, line 122
122:   def aspect
123:     width.to_f / height.to_f if !(width.blank? && height.blank?)
124:   end

Para poder reusar /documents/_share

[Source]

    # File app/models/photo.rb, line 80
80:   def body
81:     ""
82:   end

[Source]

    # File app/models/photo.rb, line 25
25:   def date
26:     date_time_original || created_at
27:   end

[Source]

    # File app/models/photo.rb, line 65
65:   def draft?
66:     !published?
67:   end

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

[Source]

     # File app/models/photo.rb, line 87
 87:   def geometry_from_file
 88:     # file = "/web/jails/agencia/home/jagencia/"+ version(:original, :relative)
 89:     file = Photo::PHOTOS_PATH + version(:original, :relative)
 90:     geometry = begin
 91:                  Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"])
 92:                rescue => err
 93:                  logger.info "No he podido coger las dimensiones de #{self.id}: #{err}"
 94:                  ""
 95:                end
 96:     if match = (geometry.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/))
 97:       match.to_a[1,2]
 98:     else
 99:       logger.info "No he podido coger las dimensiones de #{self.id}: #{geometry}"
100:       ""
101:     end
102:     # parse(geometry) ||
103:     #   raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
104:   end

True if the dimensions represent a horizontal rectangle

[Source]

     # File app/models/photo.rb, line 112
112:   def horizontal?
113:     height < width if !(width.blank? && height.blank?)
114:   end

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

[Source]

    # File app/models/photo.rb, line 60
60:   def published?
61:     albums = self.albums
62:     albums.length > 0 && albums.collect(&:draft).include?(false)
63:   end

[Source]

     # File app/models/photo.rb, line 127
127:   def set_geometry
128:     self.width, self.height = self.geometry_from_file
129:   end

Indica si se muestra en Agencia. Sólo se usa en las búsquedas

[Source]

    # File app/models/photo.rb, line 55
55:   def show_in_agencia
56:     false
57:   end

Indica si se muestra en OpenIrekia. Sólo se usa en las búsquedas

[Source]

    # File app/models/photo.rb, line 50
50:   def show_in_irekia
51:     true
52:   end

True if the dimensions represent a square

[Source]

     # File app/models/photo.rb, line 107
107:   def square?
108:     height == width  if !(width.blank? && height.blank?)
109:   end

Lista de tags par indexar. Además de los tags, incluye la ciudad, provincia y país

[Source]

    # File app/models/photo.rb, line 72
72:   def tags_for_ferret
73:     tags = tags_for_ferret_orig
74:     tags << " #{city}" unless city.nil?
75:     tags << " #{province_state}" unless province_state.nil?
76:     tags << " #{country}" unless country.nil?
77:   end

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 Photo::PHOTOS_SIZES, definido en el módulo PhotoPaths
  • path: no se usa

[Source]

    # File app/models/photo.rb, line 33
33:   def version(size=:p136, path=:absolute)
34:     if Photo::PHOTOS_SIZES.keys.include?(size)
35:       version_path = "#{File.dirname(self.file_path)}/#{size}/#{File.basename(self.file_path)}"
36:     else
37:       version_path = self.file_path
38:     end
39:     if path.eql?(:absolute)
40:       return Photo::PHOTOS_URL + version_path
41:     else
42:       return version_path
43:     end
44:   end

True if the dimensions represent a vertical rectangle

[Source]

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

[Validate]