Class: Photo

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActsAsPrioritizable
Defined in:
app/models/photo.rb

Instance Method Summary collapse

Instance Method Details

#klassObject



35
36
37
# File 'app/models/photo.rb', line 35

def klass
  read_attribute(:klass).nil? ? "" : read_attribute(:klass)
end

#thumbObject



31
32
33
# File 'app/models/photo.rb', line 31

def thumb
  asset.url(:thumb)
end

#transliterate(str) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'app/models/photo.rb', line 48

def transliterate(str)
  s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str).to_s
  s.downcase!
  s.gsub!(/'/, '')
  s.gsub!(/[^A-Za-z0-9]+/, ' ')
  s.strip!
  s.gsub!(/\ +/, '-')
  s
end

#transliterate_file_nameObject



58
59
60
61
62
# File 'app/models/photo.rb', line 58

def transliterate_file_name
  extension = File.extname(asset_file_name).gsub(/^\.+/, '')
  filename = asset_file_name.gsub(/\.#{extension}$/, '')
  self.asset.instance_write(:file_name, "#{transliterate(filename)}.#{transliterate(extension)}")
end

#which?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'app/models/photo.rb', line 39

def which?
  case klass
    when "center" then return :original
    when "left" then return :medium
    when "right" then return :medium
    when "thumb" then return :thumb 
  end
end