Class: Agave::Local::FieldType::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/agave/local/field_type/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format, size, width, height, alt, title, image_host) ⇒ Image

Returns a new instance of Image.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/agave/local/field_type/image.rb', line 36

def initialize(
  path,
  format,
  size,
  width,
  height,
  alt,
  title,
  image_host
)
  @path = path
  @format = format
  @size = size
  @width = width
  @height = height
  @title = title
  @alt = alt
  @image_host = image_host
end

Instance Attribute Details

#altObject (readonly)

Returns the value of attribute alt.



14
15
16
# File 'lib/agave/local/field_type/image.rb', line 14

def alt
  @alt
end

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/agave/local/field_type/image.rb', line 9

def format
  @format
end

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/agave/local/field_type/image.rb', line 12

def height
  @height
end

#image_hostObject (readonly)

Returns the value of attribute image_host.



15
16
17
# File 'lib/agave/local/field_type/image.rb', line 15

def image_host
  @image_host
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/agave/local/field_type/image.rb', line 8

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/agave/local/field_type/image.rb', line 10

def size
  @size
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/agave/local/field_type/image.rb', line 13

def title
  @title
end

#widthObject (readonly)

Returns the value of attribute width.



11
12
13
# File 'lib/agave/local/field_type/image.rb', line 11

def width
  @width
end

Class Method Details

.parse(upload_attributes, repo) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/agave/local/field_type/image.rb', line 17

def self.parse(upload_attributes, repo)
  return nil if !upload_attributes
  return nil if !upload_attributes[:path]
  upload = repo.entities_repo.find_entity(
    "upload", upload_attributes[:path]
  )
  return nil if !upload
  new(
    upload.path,
    upload.format,
    upload.size,
    upload.width,
    upload.height,
    upload.alt,
    upload.title,
    repo.site.entity.image_host
  )
end

Instance Method Details

#fileObject



56
57
58
59
60
61
62
# File 'lib/agave/local/field_type/image.rb', line 56

def file
  Imgix::Client.new(
    host: image_host,
    secure: true,
    include_library_param: false
  ).path(path)
end

#to_hash(*_args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/agave/local/field_type/image.rb', line 68

def to_hash(*_args)
  {
    format: format,
    size: size,
    width: width,
    height: height,
    alt: alt,
    title: title,
    url: url
  }
end

#url(opts = {}) ⇒ Object



64
65
66
# File 'lib/agave/local/field_type/image.rb', line 64

def url(opts = {})
  file.to_url(opts)
end