Class: SlideHero::Image

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, alt_text = "", width: nil, height: nil) ⇒ Image

Returns a new instance of Image.



4
5
6
7
8
9
# File 'lib/slide_hero/image.rb', line 4

def initialize(location, alt_text="", width:nil, height:nil)
  @location = location
  @alt_text = alt_text
  @width = width
  @height = height
end

Instance Attribute Details

#alt_textObject (readonly)

Returns the value of attribute alt_text.



3
4
5
# File 'lib/slide_hero/image.rb', line 3

def alt_text
  @alt_text
end

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/slide_hero/image.rb', line 3

def height
  @height
end

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/slide_hero/image.rb', line 3

def location
  @location
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/slide_hero/image.rb', line 3

def width
  @width
end

Instance Method Details

#compileObject



11
12
13
# File 'lib/slide_hero/image.rb', line 11

def compile
  %{<img#{width_attribute}#{height_attribute} src="images/#{location}" alt="#{alt_text}">}
end

#height_attributeObject



15
16
17
# File 'lib/slide_hero/image.rb', line 15

def height_attribute
  %{ height="#{height}"} if height
end

#width_attributeObject



19
20
21
# File 'lib/slide_hero/image.rb', line 19

def width_attribute
  %{ width="#{width}"} if width
end