Class: Product
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Product
- Defined in:
- app/models/product.rb
Overview
Copyright 2010-2011 Benjamin Lee Smith [email protected]
This file is part of CafePress Wrapper. CafePress Wrapper is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CafePress Wrapper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CafePress Wrapper. If not, see http://www.gnu.org/licenses/.
Constant Summary collapse
- THUMBNAIL_IMAGE_SIZE =
'100'- LARGE_IMAGE_SIZE =
'350'
Instance Method Summary collapse
- #available_in_multiple_colors? ⇒ Boolean
- #back_image_url_for_color(color_id) ⇒ Object
- #better_default_caption ⇒ Object
- #color_ids ⇒ Object
- #default_back_image ⇒ Object
- #default_front_image ⇒ Object
- #default_front_thumbnail_url ⇒ Object
- #front_image_url_for_color(color_id) ⇒ Object
- #front_thumbnail_urls ⇒ Object
- #has_back_design? ⇒ Boolean
- #has_sizes? ⇒ Boolean
- #sizes_array ⇒ Object
Instance Method Details
#available_in_multiple_colors? ⇒ Boolean
74 75 76 |
# File 'app/models/product.rb', line 74 def available_in_multiple_colors? color_ids.length > 1 end |
#back_image_url_for_color(color_id) ⇒ Object
52 53 54 |
# File 'app/models/product.rb', line 52 def back_image_url_for_color(color_id) image_urls.find_by_view_and_size_and_color_id(CafePressAPI::BACK_PRODUCT_VIEW, LARGE_IMAGE_SIZE, color_id).url end |
#better_default_caption ⇒ Object
82 83 84 |
# File 'app/models/product.rb', line 82 def better_default_caption default_caption.gsub('(dark)','').strip end |
#color_ids ⇒ Object
57 58 59 |
# File 'app/models/product.rb', line 57 def color_ids front_thumbnail_urls.map(&:color_id) end |
#default_back_image ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/product.rb', line 38 def default_back_image if default_color_id image_urls.find_by_view_and_size_and_color_id(CafePressAPI::BACK_PRODUCT_VIEW, LARGE_IMAGE_SIZE, default_color_id) else # Sometimes there is no default color returned from the API, so just pick one image_urls.find_by_view_and_size(CafePressAPI::BACK_PRODUCT_VIEW, LARGE_IMAGE_SIZE) end end |
#default_front_image ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/models/product.rb', line 29 def default_front_image if default_color_id image_urls.find_by_view_and_size_and_color_id(CafePressAPI::FRONT_PRODUCT_VIEW, LARGE_IMAGE_SIZE, default_color_id) else # Sometimes there is no default color returned from the API, so just pick one image_urls.find_by_view_and_size(CafePressAPI::FRONT_PRODUCT_VIEW, LARGE_IMAGE_SIZE) end end |
#default_front_thumbnail_url ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/models/product.rb', line 61 def default_front_thumbnail_url if default_color_id image_urls.find_by_view_and_size_and_color_id(CafePressAPI::FRONT_PRODUCT_VIEW, THUMBNAIL_IMAGE_SIZE, default_color_id).url else # Sometimes there is no default color returned from the API, so just pick one image_urls.find_by_view_and_size(CafePressAPI::FRONT_PRODUCT_VIEW, THUMBNAIL_IMAGE_SIZE).url end end |
#front_image_url_for_color(color_id) ⇒ Object
48 49 50 |
# File 'app/models/product.rb', line 48 def front_image_url_for_color(color_id) image_urls.find_by_view_and_size_and_color_id(CafePressAPI::FRONT_PRODUCT_VIEW, LARGE_IMAGE_SIZE, color_id).url end |
#front_thumbnail_urls ⇒ Object
25 26 27 |
# File 'app/models/product.rb', line 25 def front_thumbnail_urls image_urls.find_all_by_view_and_size(CafePressAPI::FRONT_PRODUCT_VIEW, THUMBNAIL_IMAGE_SIZE) end |
#has_back_design? ⇒ Boolean
86 87 88 |
# File 'app/models/product.rb', line 86 def has_back_design? store.cafepress_back_design_url end |
#has_sizes? ⇒ Boolean
78 79 80 |
# File 'app/models/product.rb', line 78 def has_sizes? sizes.length > 0 end |
#sizes_array ⇒ Object
70 71 72 |
# File 'app/models/product.rb', line 70 def sizes_array sizes.collect{|s| [s.full_name, s.cafepress_size_id]} end |