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 ⇒ 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
82 83 84 |
# File 'app/models/lentil/image.rb', line 82 def self.approved where(state: self::States[:approved]).where(:suppressed => false) end |
.approved_all ⇒ Object
86 87 88 |
# File 'app/models/lentil/image.rb', line 86 def self.approved_all where(state: self::States[:approved]) end |
.blend ⇒ Object
90 91 92 |
# File 'app/models/lentil/image.rb', line 90 def self.blend (popular.limit(50) + recent.limit(100) + staff_picks.limit(150)).uniq.shuffle end |
.popular ⇒ Object
78 79 80 |
# File 'app/models/lentil/image.rb', line 78 def self.popular order("popular_score DESC").order("like_votes_count DESC") end |
.recent ⇒ Object
70 71 72 |
# File 'app/models/lentil/image.rb', line 70 def self.recent order("original_datetime DESC") end |
.search(page, number_to_show = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/models/lentil/image.rb', line 62 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
74 75 76 |
# File 'app/models/lentil/image.rb', line 74 def self.staff_picks where(:staff_like => true).order("original_datetime DESC") end |
Instance Method Details
#available_staff_tags(all_tags) ⇒ Object
114 115 116 117 118 119 120 |
# File 'app/models/lentil/image.rb', line 114 def () = - (self. - self.) if .length > 0 = .sort_by(&:name) end end |
#battles ⇒ Object
122 123 124 |
# File 'app/models/lentil/image.rb', line 122 def battles self.won_battles + self.lost_battles end |
#battles_count ⇒ Object
126 127 128 |
# File 'app/models/lentil/image.rb', line 126 def battles_count self.wins_count + self.losses_count end |
#image_url ⇒ Object
legacy
131 132 133 |
# File 'app/models/lentil/image.rb', line 131 def image_url large_url end |
#jpeg ⇒ Object
legacy
136 137 138 |
# File 'app/models/lentil/image.rb', line 136 def jpeg large_url end |
#large_url(protocol_relative = true) ⇒ Object
145 146 147 148 149 150 151 |
# File 'app/models/lentil/image.rb', line 145 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
153 154 155 156 157 158 159 |
# File 'app/models/lentil/image.rb', line 153 def medium_url(protocol_relative = true) if protocol_relative protocol_relative_url + 'media/?size=m' else url + 'media/?size=m' end end |
#original_metadata ⇒ Object
193 194 195 |
# File 'app/models/lentil/image.rb', line 193 def Oj.load(Emojimmy.token_to_emoji(super.to_json)) end |
#original_metadata=(meta) ⇒ Object
189 190 191 |
# File 'app/models/lentil/image.rb', line 189 def () write_attribute(:original_metadata, Oj.load(Emojimmy.emoji_to_token(.to_hash.to_json))) end |
#protocol_relative_url ⇒ Object
140 141 142 143 |
# File 'app/models/lentil/image.rb', line 140 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
94 95 96 97 98 99 100 101 102 |
# File 'app/models/lentil/image.rb', line 94 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
104 105 106 107 108 109 110 111 112 |
# File 'app/models/lentil/image.rb', line 104 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
161 162 163 164 165 166 167 |
# File 'app/models/lentil/image.rb', line 161 def thumbnail_url(protocol_relative = true) if protocol_relative protocol_relative_url + 'media/?size=t' else url + 'media/?size=t' end end |