Class: Prismic::Fragments::Image::View

Inherits:
Fragment
  • Object
show all
Defined in:
lib/prismic/fragments/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fragment

#as_text

Constructor Details

#initialize(url, width, height, alt, copyright, link_to) ⇒ View

Returns a new instance of View.



41
42
43
44
45
46
47
48
# File 'lib/prismic/fragments/image.rb', line 41

def initialize(url, width, height, alt, copyright, link_to)
  @url = url
  @width = width
  @height = height
  @alt = alt
  @copyright = copyright
  @link_to = link_to
end

Instance Attribute Details

#altObject

Returns the value of attribute alt.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def alt
  @alt
end

Returns the value of attribute copyright.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def copyright
  @copyright
end

#heightObject

Returns the value of attribute height.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def height
  @height
end

Returns the value of attribute link_to.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def link_to
  @link_to
end

#urlObject

Returns the value of attribute url.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def url
  @url
end

#widthObject

Returns the value of attribute width.



39
40
41
# File 'lib/prismic/fragments/image.rb', line 39

def width
  @width
end

Instance Method Details

#as_html(link_resolver = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/prismic/fragments/image.rb', line 54

def as_html(link_resolver=nil)
  html = []
  html << (link_to.nil? ? '' : link_to.start_html(link_resolver, link_to.target))
  html << %(<img src="#@url" alt="#@alt" width="#@width" height="#@height" />)
  html << (link_to.nil? ? '' : link_to.end_html)
  html.join
end

#ratioObject



50
51
52
# File 'lib/prismic/fragments/image.rb', line 50

def ratio
  return @width / @height
end