Skip to content

Commit

Permalink
Rename column Book#pages -> Book#page_count
Browse files Browse the repository at this point in the history
  • Loading branch information
bloopletech committed Jun 12, 2015
1 parent b06bbde commit dcb5155
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
20 changes: 10 additions & 10 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def info

@oldest_book = Book.order('published_on ASC').first
@newest_book = Book.order('published_on DESC').first
@longest_book = Book.order('pages DESC').first
@shortest_book = Book.order('pages ASC').first
@longest_book = Book.order('page_count DESC').first
@shortest_book = Book.order('page_count ASC').first
@most_popular_book = Book.order('opens DESC').first
@least_popular_book = Book.order('opens ASC').first

@oldest_video = Video.order('published_on ASC').first
@newest_video = Video.order('published_on DESC').first
@longest_video = Video.order('pages DESC').first
@shortest_video = Video.order('pages ASC').first
@longest_video = Video.order('page_count DESC').first
@shortest_video = Video.order('page_count ASC').first
@most_popular_video = Video.order('opens DESC').first
@least_popular_video = Video.order('opens ASC').first
end
Expand Down Expand Up @@ -91,12 +91,12 @@ def _search_results
results = results.where("opens > 3") if excluded_terms.delete 's:readish'
results = results.where("opens = 0") if included_terms.delete 's:unread'
results = results.where("opens > 0") if excluded_terms.delete 's:unread'
results = results.where("pages >= 150") if included_terms.delete 's:tank'
results = results.where("pages < 150") if excluded_terms.delete 's:tank'
results = results.where("pages >= 80") if included_terms.delete 's:long'
results = results.where("pages < 80") if excluded_terms.delete 's:long'
results = results.where("pages <= 30") if included_terms.delete 's:short'
results = results.where("pages > 30") if excluded_terms.delete 's:short'
results = results.where("page_count >= 150") if included_terms.delete 's:tank'
results = results.where("page_count < 150") if excluded_terms.delete 's:tank'
results = results.where("page_count >= 80") if included_terms.delete 's:long'
results = results.where("page_count < 80") if excluded_terms.delete 's:long'
results = results.where("page_count <= 30") if included_terms.delete 's:short'
results = results.where("page_count > 30") if excluded_terms.delete 's:short'
#results = results.where("COUNT(taggings.id) > 0") if included_tags.delete 's:tagged'

unless excluded_terms.empty?
Expand Down
4 changes: 2 additions & 2 deletions app/views/items/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="wrapper">
<%
many_opens = item.opens >= 10
many_pages = item.pages >= 50
many_pages = item.page_count >= 50
%>
<% if many_opens || many_pages %>
<div class="emblems">
Expand All @@ -28,7 +28,7 @@
<%= form_for item.becomes(Item), :remote => true do |f| %>
<%= f.text_field :tag_list, :class => 'input' %>
<% end %>
<%= image_tag("icons/page_white.png", :title => "Pages") %> <%= item.pages %>&nbsp;&nbsp;
<%= image_tag("icons/page_white.png", :title => "Pages") %> <%= item.page_count %>&nbsp;&nbsp;
<%= image_tag("icons/application_go.png", :title => "Opens") %> <span class="opens"><%= item.opens %></span><br>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions app/views/items/info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<p>The oldest book was published on <%= link_to(@oldest_book.published_on, @oldest_book, :target => "_blank") %>
and the newest book was published <%= link_to(@newest_book.published_on, @newest_book, :target => "_blank") %>.</p>

<p>The longest book has <%= link_to(pluralize(number_with_delimiter(@longest_book.pages), 'page'), @longest_book, :target => "_blank") %> and the
shortest has <%= link_to(pluralize(number_with_delimiter(@shortest_book.pages), 'page'), @shortest_book, :target => "_blank") %>.</p>
<p>Together, your books have <%= pluralize(number_with_precision(Book.sum('pages'), prec_opts), 'page') %>. The average number of pages is <%= number_with_precision(Book.average('pages'), prec_opts) %>, and the most common page count for a book is <%= number_with_precision(Book.average('pages'), prec_opts) %>.</p>
<p>The longest book has <%= link_to(pluralize(number_with_delimiter(@longest_book.page_count), 'page'), @longest_book, :target => "_blank") %> and the
shortest has <%= link_to(pluralize(number_with_delimiter(@shortest_book.page_count), 'page'), @shortest_book, :target => "_blank") %>.</p>
<p>Together, your books have <%= pluralize(number_with_precision(Book.sum('page_count'), prec_opts), 'page') %>. The average number of pages is <%= number_with_precision(Book.average('page_count'), prec_opts) %>, and the most common page count for a book is <%= number_with_precision(Book.average('page_count'), prec_opts) %>.</p>

<p>The most popular book in your collection has been opened
<%= link_to(pluralize(number_with_delimiter(@most_popular_book.opens), 'time'), @most_popular_book, :target => "_blank") %>,
and the least popular opened <%= link_to(pluralize(number_with_delimiter(@least_popular_book.opens), 'time'), @least_popular_book, :target => "_blank") %>,
with an average of <%= pluralize(number_with_precision(Book.average('opens'), prec_opts), 'open') %> per book.</p>

<p><%= link_to(pluralize(number_with_delimiter(Book.count(:conditions => 'opens > 0')), 'book has', 'books have'), items_with(:search => 's:read'), :target => "_blank") %>
been opened at least once, and <%= link_to(pluralize(number_with_delimiter(Book.count(:conditions => 'opens = 0')), 'book has', 'books have'), items_with(:search => 's:unread'), :target => '_blank') %>
never been opened at all.</p>
Expand All @@ -23,12 +23,12 @@
<% unless Video.count.zero? %>
<p>The oldest video was published on <%= link_to(@oldest_video.published_on, @oldest_video, :target => "_blank") %>
and the newest video was published <%= link_to(@newest_video.published_on, @newest_video, :target => "_blank") %>.</p>

<p>The most popular video in your collection has been opened
<%= link_to(pluralize(number_with_delimiter(@most_popular_video.opens), 'time'), @most_popular_video, :target => "_blank") %>,
and the least popular opened <%= link_to(pluralize(number_with_delimiter(@least_popular_video.opens), 'time'), @least_popular_video, :target => "_blank") %>,
with an average of <%= pluralize(number_with_precision(Video.average('opens'), prec_opts), 'open') %> per video.</p>

<p><%= link_to(pluralize(number_with_delimiter(Video.count(:conditions => 'opens > 0')), 'video has', 'videos have'), items_with(:search => 's:read'), :target => "_blank") %>
been opened at least once, and <%= link_to(pluralize(number_with_delimiter(Video.count(:conditions => 'opens = 0')), 'video has', 'videos have'), items_with(:search => 's:unread'), :target => '_blank') %>
never been opened at all.</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/more_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= image_tag(@item.preview.thumbnail.url, :class => 'title_image') %>
<div id="info">
<span class="title"><%= h @item.title %></span><br>
Pages <%= image_tag("icons/page_white.png", :title => "Pages") %> <%= @item.pages %><br>
Pages <%= image_tag("icons/page_white.png", :title => "Pages") %> <%= @item.page_count %><br>
Opens <%= image_tag("icons/application_go.png", :title => "Opens") %>: <%= @item.opens %><br>
Published: <%= @item.published_on %><br>
Added: <%= @item.created_at %><br>
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20150611112937_rename_page_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RenamePageCount < ActiveRecord::Migration
def up
rename_column :items, :pages, :page_count
end

def down
rename_column :items, :page_count, :pages
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20101117123828) do
ActiveRecord::Schema.define(:version => 20150611112937) do

create_table "collections", :force => true do |t|
t.string "path"
Expand All @@ -27,7 +27,7 @@
t.text "filename"
t.text "preview"
t.integer "opens", :default => 0
t.integer "pages", :default => 0
t.integer "page_count", :default => 0
t.datetime "published_on"
t.datetime "created_at"
t.datetime "updated_at"
Expand Down

0 comments on commit dcb5155

Please sign in to comment.