Class: Comic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comic
- Includes:
- Entity, Lockable, Postable
- Defined in:
- app/models/comic.rb
Constant Summary collapse
- MONDAY =
1- WEDNESDAY =
3- FRIDAY =
5- VALID_DAYS =
[MONDAY, WEDNESDAY, FRIDAY]
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_url ⇒ 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
79 80 81 82 |
# File 'app/models/comic.rb', line 79 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
146 147 148 149 150 |
# File 'app/models/comic.rb', line 146 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
142 143 144 |
# File 'app/models/comic.rb', line 142 def current_created reverse_numerical.first end |
.feed ⇒ Object
134 135 136 |
# File 'app/models/comic.rb', line 134 def feed posted.reverse_numerical.take 10 end |
.from_number(num, only_posted = false) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/comic.rb', line 158 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
122 123 124 |
# File 'app/models/comic.rb', line 122 def largest_number preview_current.number end |
.largest_posted_number ⇒ Object
118 119 120 |
# File 'app/models/comic.rb', line 118 def largest_posted_number current.number end |
.next_number(comic) ⇒ Object
98 99 100 101 102 103 104 |
# File 'app/models/comic.rb', line 98 def next_number(comic) if comic comic.number + 1 else 1 end end |
.next_post_date(comic) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/comic.rb', line 106 def next_post_date(comic) if comic from = comic.posted_at else from = Date.today end result = from result += 1.day until result > from && VALID_DAYS.include?(result.wday) result end |
.numerical ⇒ Object
130 131 132 |
# File 'app/models/comic.rb', line 130 def numerical order "comics.number ASC" end |
.preview_current ⇒ Object
152 153 154 155 156 |
# File 'app/models/comic.rb', line 152 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
126 127 128 |
# File 'app/models/comic.rb', line 126 def reverse_numerical order "comics.number DESC" end |
.search(query) ⇒ Object
75 76 77 |
# File 'app/models/comic.rb', line 75 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
138 139 140 |
# File 'app/models/comic.rb', line 138 def sitemap posted.reverse_numerical.all end |
.update_comic(params) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/comic.rb', line 84 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
64 65 66 |
# File 'app/models/comic.rb', line 64 def absolute_img_url "http://#{Setting[:domain]}#{img_url}" end |
#edit_url ⇒ Object
22 23 24 |
# File 'app/models/comic.rb', line 22 def edit_url "/admin/comic/#{number}/edit" end |
#formatted_description ⇒ Object
26 27 28 |
# File 'app/models/comic.rb', line 26 def formatted_description Markdown.render description end |
#img_url ⇒ Object
56 57 58 |
# File 'app/models/comic.rb', line 56 def img_url "/comic/#{number}.png" end |
#maybe_newest? ⇒ Boolean
50 51 52 53 54 |
# File 'app/models/comic.rb', line 50 def maybe_newest? if respond_to? :max_number max_number.to_i == number end end |
#next_number ⇒ Object
40 41 42 43 44 |
# File 'app/models/comic.rb', line 40 def next_number if number number + 1 end end |
#oldest? ⇒ Boolean
46 47 48 |
# File 'app/models/comic.rb', line 46 def oldest? number == 1 || !number end |
#preview_img_url ⇒ Object
60 61 62 |
# File 'app/models/comic.rb', line 60 def preview_img_url "/admin/comic/#{number}/preview.png" end |
#preview_url ⇒ Object
14 15 16 |
# File 'app/models/comic.rb', line 14 def preview_url "/admin/comic/#{number}/preview" end |
#previous_number ⇒ Object
34 35 36 37 38 |
# File 'app/models/comic.rb', line 34 def previous_number if number number - 1 end end |
#real? ⇒ Boolean
30 31 32 |
# File 'app/models/comic.rb', line 30 def real? number end |
#url ⇒ Object
18 19 20 |
# File 'app/models/comic.rb', line 18 def url "/comic/#{number}" end |