Class: PlainRecord::Extra::Image::Data
- Inherits:
-
Object
- Object
- PlainRecord::Extra::Image::Data
- Defined in:
- lib/plain_record/extra/image.rb
Overview
Field value object with image paths and URL.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Converted image file.
-
#height ⇒ Object
readonly
Image height.
-
#original ⇒ Object
readonly
Original image file.
-
#size ⇒ Object
readonly
Format of image size.
-
#size_name ⇒ Object
readonly
Name of image size.
-
#url ⇒ Object
readonly
Converted image URL.
-
#width ⇒ Object
readonly
Image width.
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(entry, field, size) ⇒ Data
constructor
Set image paths.
Constructor Details
#initialize(entry, field, size) ⇒ Data
Set image paths.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/plain_record/extra/image.rb', line 172 def initialize(entry, field, size) @size_name = size @original = entry.class.get_image_from(entry, field) if size @size = entry.class.image_sizes[field][size] unless @size raise ArgumentError, "Field `#{field}` doesn't have `#{size}` size" end @width, @height = @size.split('x').map { |i| i.to_i } end if size or entry.class.image_sizes[field].empty? @url = entry.class.get_image_url(entry, field, size) @file = entry.class.get_image_file(entry, field, size) end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Converted image file.
166 167 168 |
# File 'lib/plain_record/extra/image.rb', line 166 def file @file end |
#height ⇒ Object (readonly)
Image height.
160 161 162 |
# File 'lib/plain_record/extra/image.rb', line 160 def height @height end |
#original ⇒ Object (readonly)
Original image file.
169 170 171 |
# File 'lib/plain_record/extra/image.rb', line 169 def original @original end |
#size ⇒ Object (readonly)
Format of image size.
154 155 156 |
# File 'lib/plain_record/extra/image.rb', line 154 def size @size end |
#size_name ⇒ Object (readonly)
Name of image size.
151 152 153 |
# File 'lib/plain_record/extra/image.rb', line 151 def size_name @size_name end |
#url ⇒ Object (readonly)
Converted image URL.
163 164 165 |
# File 'lib/plain_record/extra/image.rb', line 163 def url @url end |
#width ⇒ Object (readonly)
Image width.
157 158 159 |
# File 'lib/plain_record/extra/image.rb', line 157 def width @width end |
Instance Method Details
#exists? ⇒ Boolean
190 191 192 |
# File 'lib/plain_record/extra/image.rb', line 190 def exists? File.exists? @original end |