Class: PlainRecord::Extra::Image::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/plain_record/extra/image.rb

Overview

Field value object with image paths and URL.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly)

Converted image file.



166
167
168
# File 'lib/plain_record/extra/image.rb', line 166

def file
  @file
end

#heightObject (readonly)

Image height.



160
161
162
# File 'lib/plain_record/extra/image.rb', line 160

def height
  @height
end

#originalObject (readonly)

Original image file.



169
170
171
# File 'lib/plain_record/extra/image.rb', line 169

def original
  @original
end

#sizeObject (readonly)

Format of image size.



154
155
156
# File 'lib/plain_record/extra/image.rb', line 154

def size
  @size
end

#size_nameObject (readonly)

Name of image size.



151
152
153
# File 'lib/plain_record/extra/image.rb', line 151

def size_name
  @size_name
end

#urlObject (readonly)

Converted image URL.



163
164
165
# File 'lib/plain_record/extra/image.rb', line 163

def url
  @url
end

#widthObject (readonly)

Image width.



157
158
159
# File 'lib/plain_record/extra/image.rb', line 157

def width
  @width
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/plain_record/extra/image.rb', line 190

def exists?
  File.exists? @original
end