Class: Lentil::Image
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lentil::Image
- Defined in:
- app/models/lentil/image.rb
Overview
Schema Information
Table name: lentil_images
id :integer not null, primary key
description :text
created_at :datetime not null
updated_at :datetime not null
like_votes_count :integer default(0)
url :string(255)
user_id :integer
state :integer default(0)
external_identifier :string(255)
long_url :string(255)
original_metadata :text
original_datetime :datetime
staff_like :boolean default(FALSE)
moderator_id :integer
moderated_at :datetime
second_moderation :boolean default(FALSE)
wins_count :integer default(0)
losses_count :integer default(0)
win_pct :float
popular_score :integer default(0)
file_harvested_date :datetime
file_harvest_failed :integer default(0)
donor_agreement_submitted_date :datetime
donor_agreement_failed :integer default(0)
failed_file_checks :integer default(0)
file_last_checked :datetime
donor_agreement_rejected :datetime
do_not_request_donation :boolean
Constant Summary collapse
- States =
{ :pending => 0, :approved => 1, :rejected => 2, }
Class Method Summary collapse
- .approved ⇒ Object
- .approved_all ⇒ Object
- .blend ⇒ Object
- .popular ⇒ Object
- .recent ⇒ Object
- .search(page, number_to_show = nil) ⇒ Object
- .staff_picks ⇒ Object
Instance Method Summary collapse
- #available_staff_tags(all_tags) ⇒ Object
- #battles ⇒ Object
- #battles_count ⇒ Object
-
#image_url ⇒ Object
legacy.
-
#jpeg ⇒ Object
legacy.
- #large_url(protocol_relative = true) ⇒ Object
- #medium_url(protocol_relative = true) ⇒ Object
- #original_metadata=(meta) ⇒ Object
- #protocol_relative_url ⇒ Object
- #service_tags ⇒ Object
- #staff_tags ⇒ Object
- #thumbnail_url(protocol_relative = true) ⇒ Object
Class Method Details
.approved ⇒ Object
87 88 89 |
# File 'app/models/lentil/image.rb', line 87 def self.approved where(state: self::States[:approved]).where(:suppressed => false) end |
.approved_all ⇒ Object
91 92 93 |
# File 'app/models/lentil/image.rb', line 91 def self.approved_all where(state: self::States[:approved]) end |
.blend ⇒ Object
95 96 97 |
# File 'app/models/lentil/image.rb', line 95 def self.blend (popular.limit(50) + recent.limit(100) + staff_picks.limit(150)).uniq.shuffle end |
.popular ⇒ Object
83 84 85 |
# File 'app/models/lentil/image.rb', line 83 def self.popular order("popular_score DESC").order("like_votes_count DESC") end |
.recent ⇒ Object
75 76 77 |
# File 'app/models/lentil/image.rb', line 75 def self.recent order("original_datetime DESC") end |
.search(page, number_to_show = nil) ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/models/lentil/image.rb', line 67 def self.search(page, number_to_show = nil) unless number_to_show.nil? paginate :per_page => 20, :page => page, :total_entries => number_to_show else paginate :per_page => 20, :page => page end end |
.staff_picks ⇒ Object
79 80 81 |
# File 'app/models/lentil/image.rb', line 79 def self.staff_picks where(:staff_like => true).order("original_datetime DESC") end |
Instance Method Details
#available_staff_tags(all_tags) ⇒ Object
119 120 121 122 123 124 125 |
# File 'app/models/lentil/image.rb', line 119 def () = - (self. - self.) if .length > 0 = .sort_by(&:name) end end |
#battles ⇒ Object
127 128 129 |
# File 'app/models/lentil/image.rb', line 127 def battles self.won_battles + self.lost_battles end |
#battles_count ⇒ Object
131 132 133 |
# File 'app/models/lentil/image.rb', line 131 def battles_count self.wins_count + self.losses_count end |
#image_url ⇒ Object
legacy
136 137 138 |
# File 'app/models/lentil/image.rb', line 136 def image_url large_url end |
#jpeg ⇒ Object
legacy
141 142 143 |
# File 'app/models/lentil/image.rb', line 141 def jpeg large_url end |
#large_url(protocol_relative = true) ⇒ Object
150 151 152 153 154 155 156 |
# File 'app/models/lentil/image.rb', line 150 def large_url(protocol_relative = true) if protocol_relative protocol_relative_url + 'media/?size=l' else url + 'media/?size=l' end end |
#medium_url(protocol_relative = true) ⇒ Object
158 159 160 161 162 163 164 |
# File 'app/models/lentil/image.rb', line 158 def medium_url(protocol_relative = true) if protocol_relative protocol_relative_url + 'media/?size=m' else url + 'media/?size=m' end end |
#original_metadata=(meta) ⇒ Object
194 195 196 |
# File 'app/models/lentil/image.rb', line 194 def () write_attribute(:original_metadata, .to_hash) end |
#protocol_relative_url ⇒ Object
145 146 147 148 |
# File 'app/models/lentil/image.rb', line 145 def protocol_relative_url # instagr.am returns 301 to instagram.com and invalid SSL certificate url.sub(/^http:/, '').sub(/\/\/instagr\.am/, '//instagram.com') end |
#service_tags ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'app/models/lentil/image.rb', line 99 def begin tag_ids = self.taggings.select { |tagging| tagging.staff_tag == false }.map(&:tag_id) = self..select { |tag| tag_ids.include? tag.id}.sort_by(&:name) rescue Rails.logger.error "Error retrieving service_tags" = [] end end |
#staff_tags ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'app/models/lentil/image.rb', line 109 def begin tag_ids = self.taggings.select { |tagging| tagging.staff_tag == true }.map(&:tag_id) = self..select { |tag| tag_ids.include? tag.id}.sort_by(&:name) rescue Rails.logger.error "Error retrieving staff_tags" = [] end end |
#thumbnail_url(protocol_relative = true) ⇒ Object
166 167 168 169 170 171 172 |
# File 'app/models/lentil/image.rb', line 166 def thumbnail_url(protocol_relative = true) if protocol_relative protocol_relative_url + 'media/?size=t' else url + 'media/?size=t' end end |