Class: FamilyGallery::Picture

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/family_gallery/picture.rb

Instance Method Summary collapse

Instance Method Details

#height_for_width(new_width) ⇒ Object



23
24
25
# File 'app/models/family_gallery/picture.rb', line 23

def height_for_width(new_width)
  return (height.to_f / (width.to_f / new_width.to_f)).to_i
end

#location?Boolean



50
51
52
# File 'app/models/family_gallery/picture.rb', line 50

def location?
  latitude? && longitude?
end

#next_picture_in_group(group) ⇒ Object



35
36
37
38
39
40
# File 'app/models/family_gallery/picture.rb', line 35

def next_picture_in_group(group)
  group.pictures
    .where("family_gallery_pictures.id > ?", id)
    .order(:id)
    .first
end

#previous_picture_in_group(group) ⇒ Object



42
43
44
45
46
47
48
# File 'app/models/family_gallery/picture.rb', line 42

def previous_picture_in_group(group)
  group.pictures
    .where("family_gallery_pictures.id < ?", id)
    .order(:id)
    .reverse_order
    .first
end

#smartsize(size) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/family_gallery/picture.rb', line 27

def smartsize(size)
  if height > width
    return {width: width_for_height(size), height: size}
  else
    return {width: size, height: height_for_width(size)}
  end
end

#width_for_height(new_height) ⇒ Object



19
20
21
# File 'app/models/family_gallery/picture.rb', line 19

def width_for_height(new_height)
  return (width.to_f / (height.to_f / new_height.to_f)).to_i
end