Class: Comic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comic
- Includes:
- Entity, Lockable, Postable
- Defined in:
- app/models/comic.rb
Constant Summary collapse
- SUNDAY =
0- MONDAY =
1- TUESDAY =
2- WEDNESDAY =
3- THURSDAY =
4- FRIDAY =
5- SATURDAY =
6- DAY_CONVERSION =
{ :sunday => SUNDAY, :monday => MONDAY, :tuesday => TUESDAY, :wednesday => WEDNESDAY, :thursday => THURSDAY, :friday => FRIDAY, :saturday => SATURDAY }
Class Method Summary collapse
- .create_comic(params) ⇒ Object
- .current ⇒ Object
- .current_created ⇒ Object
- .feed ⇒ Object
- .from_number(num, only_posted = false) ⇒ Object
- .largest_number ⇒ Object
- .largest_posted_number ⇒ Object
- .next_number(comic) ⇒ Object
- .next_post_date(comic) ⇒ Object
- .numerical ⇒ Object
- .preview_current ⇒ Object
- .reverse_numerical ⇒ Object
- .search(query) ⇒ Object
- .sitemap ⇒ Object
- .update_comic(params) ⇒ Object
Instance Method Summary collapse
- #absolute_img_url ⇒ Object
- #edit_url ⇒ Object
- #formatted_description ⇒ Object
- #img_height ⇒ Object
- #img_url ⇒ Object
- #img_width ⇒ Object
- #magick ⇒ Object
- #maybe_newest? ⇒ Boolean
- #next_number ⇒ Object
- #oldest? ⇒ Boolean
- #preview_img_url ⇒ Object
- #preview_url ⇒ Object
- #previous_number ⇒ Object
- #real? ⇒ Boolean
- #url ⇒ Object
Class Method Details
.create_comic(params) ⇒ Object
107 108 109 110 |
# File 'app/models/comic.rb', line 107 def create_comic(params) last = current_created create :number => next_number(last), :title => params[:title], :posted_at => next_post_date(last), :description => params[:description], :scene_description => params[:scene_description], :dialogue => params[:dialogue], :title_text => params[:title_text], :database_file => DatabaseFile.create_from_param(params[:image], :allowed_extensions => ["png"]), :locked => true end |
.current ⇒ Object
176 177 178 179 180 |
# File 'app/models/comic.rb', line 176 def current comic = posted.reverse_numerical.first comic = new :title => "No Comics Yet", :description => "Check back later for the first comic!" unless comic comic end |
.current_created ⇒ Object
172 173 174 |
# File 'app/models/comic.rb', line 172 def current_created reverse_numerical.first end |
.feed ⇒ Object
164 165 166 |
# File 'app/models/comic.rb', line 164 def feed posted.reverse_numerical.take 10 end |
.from_number(num, only_posted = false) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/models/comic.rb', line 188 def from_number(num, only_posted = false) comic = where :number => num.to_i if only_posted max_number = Comic.posted.select("MAX(comics.number)").to_sql comic = comic.posted.select("comics.*, (#{max_number}) AS max_number") else max_number = Comic.select("MAX(comics.number)").to_sql comic = comic.select("comics.*, (#{max_number}) AS max_number") end comic = comic.first raise ActiveRecord::RecordNotFound.new("No records found!") unless comic comic end |
.largest_number ⇒ Object
152 153 154 |
# File 'app/models/comic.rb', line 152 def largest_number preview_current.number end |
.largest_posted_number ⇒ Object
148 149 150 |
# File 'app/models/comic.rb', line 148 def largest_posted_number current.number end |
.next_number(comic) ⇒ Object
126 127 128 129 130 131 132 |
# File 'app/models/comic.rb', line 126 def next_number(comic) if comic comic.number + 1 else 1 end end |
.next_post_date(comic) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/models/comic.rb', line 134 def next_post_date(comic) if comic from = comic.posted_at else from = Date.today end valid_days = Setting[:schedule].map { |x| DAY_CONVERSION[x] } result = from result += 1.day until result > from && valid_days.include?(result.wday) result end |
.numerical ⇒ Object
160 161 162 |
# File 'app/models/comic.rb', line 160 def numerical order "comics.number ASC" end |
.preview_current ⇒ Object
182 183 184 185 186 |
# File 'app/models/comic.rb', line 182 def preview_current comic = reverse_numerical.first comic = new :title => "No Comics Yet", :description => "Check back later for the first comic!" unless comic comic end |
.reverse_numerical ⇒ Object
156 157 158 |
# File 'app/models/comic.rb', line 156 def reverse_numerical order "comics.number DESC" end |
.search(query) ⇒ Object
103 104 105 |
# File 'app/models/comic.rb', line 103 def search(query) reverse_numerical.where "LOWER(title) LIKE :query OR LOWER(description) LIKE :query OR LOWER(scene_description) LIKE :query OR LOWER(dialogue) LIKE :query OR LOWER(title_text) LIKE :query", :query => "%#{query.downcase}%" end |
.sitemap ⇒ Object
168 169 170 |
# File 'app/models/comic.rb', line 168 def sitemap posted.reverse_numerical.to_a end |
.update_comic(params) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/comic.rb', line 112 def update_comic(params) comic = from_number params[:id].to_i comic.ensure_unlocked! comic.title = params[:title] comic.description = params[:description] comic.scene_description = params[:scene_description] comic.dialogue = params[:dialogue] comic.title_text = params[:title_text] comic.locked = true comic.database_file = DatabaseFile.create_from_param params[:image], :allowed_extensions => ["png"] if params[:image] comic.save! comic end |
Instance Method Details
#absolute_img_url ⇒ Object
80 81 82 |
# File 'app/models/comic.rb', line 80 def absolute_img_url "http://#{Setting[:domain]}#{img_url}" end |
#edit_url ⇒ Object
23 24 25 |
# File 'app/models/comic.rb', line 23 def edit_url "/admin/comic/#{number}/edit" end |
#formatted_description ⇒ Object
27 28 29 |
# File 'app/models/comic.rb', line 27 def formatted_description Markdown.render description end |
#img_height ⇒ Object
68 69 70 |
# File 'app/models/comic.rb', line 68 def img_height magick.rows end |
#img_url ⇒ Object
72 73 74 |
# File 'app/models/comic.rb', line 72 def img_url "/comic/#{number}.png" end |
#img_width ⇒ Object
64 65 66 |
# File 'app/models/comic.rb', line 64 def img_width magick.columns end |
#magick ⇒ Object
57 58 59 60 61 62 |
# File 'app/models/comic.rb', line 57 def magick return @magick if @magick images = Magick::Image.from_blob database_file.content raise "Only 1 image is allowed!" if images.size != 1 @magick = images.first end |
#maybe_newest? ⇒ Boolean
51 52 53 54 55 |
# File 'app/models/comic.rb', line 51 def maybe_newest? if respond_to? :max_number max_number.to_i == number end end |
#next_number ⇒ Object
41 42 43 44 45 |
# File 'app/models/comic.rb', line 41 def next_number if number number + 1 end end |
#oldest? ⇒ Boolean
47 48 49 |
# File 'app/models/comic.rb', line 47 def oldest? number == 1 || !number end |
#preview_img_url ⇒ Object
76 77 78 |
# File 'app/models/comic.rb', line 76 def preview_img_url "/admin/comic/#{number}/preview.png" end |
#preview_url ⇒ Object
15 16 17 |
# File 'app/models/comic.rb', line 15 def preview_url "/admin/comic/#{number}/preview" end |
#previous_number ⇒ Object
35 36 37 38 39 |
# File 'app/models/comic.rb', line 35 def previous_number if number number - 1 end end |
#real? ⇒ Boolean
31 32 33 |
# File 'app/models/comic.rb', line 31 def real? number end |
#url ⇒ Object
19 20 21 |
# File 'app/models/comic.rb', line 19 def url "/comic/#{number}" end |