Class: JustimmoClient::V1::Attachment

Inherits:
JustimmoBase show all
Defined in:
lib/justimmo_client/api/v1/models/attachment.rb

Instance Method Summary collapse

Methods inherited from JustimmoBase

#==, #save!, #to_h

Methods included from Utils

#autoload_dir, #translate

Methods included from Logging

default_logger, #logger, rails_logger

Instance Method Details

#inspectObject



38
39
40
# File 'lib/justimmo_client/api/v1/models/attachment.rb', line 38

def inspect
  "#<#{self.class} #{self}>"
end

#url(size = nil) ⇒ Object Also known as: to_s, []



30
31
32
33
# File 'lib/justimmo_client/api/v1/models/attachment.rb', line 30

def url(size = nil)
  size ||= @size
  "#{BASE_URL}/#{@type}/#{size}/#{file}.#{format}"
end

#url=(value) ⇒ Object

FIXME: the attachment can be something other than a image file

maybe move type detection into representer?


21
22
23
24
25
26
27
28
# File 'lib/justimmo_client/api/v1/models/attachment.rb', line 21

def url=(value)
  path = URI.parse(value).path.sub("/public/", "")
  @type, size, file = path.split("/")
  return if file.nil?
  @format ||= ::File.extname(file).tr(".", "")
  @file = ::File.basename(file, ".#{@format}")
  @size = size.start_with?("user") ? :user_big : :big
end