class Feeligo::Stickers::StickerImageTag

Public Class Methods

new(path, opts) click to toggle source
# File lib/feeligo/stickers/sticker_image_tag.rb, line 6
def initialize path, opts
  @path = path
  @opts = opts
end

Public Instance Methods

to_s() click to toggle source
# File lib/feeligo/stickers/sticker_image_tag.rb, line 12
def to_s
  code = build_tag
  if code.respond_to?(:html_safe) then code.html_safe else code end
end

Protected Instance Methods

build_tag() click to toggle source

The <img> tag

# File lib/feeligo/stickers/sticker_image_tag.rb, line 24
def build_tag
  "<img " << tag_attributes_string << "/>"
end
image_url() click to toggle source

The URL of the image

# File lib/feeligo/stickers/sticker_image_tag.rb, line 47
def image_url
  return "" if @path.nil? || @path.empty?
  "#{images_scheme}://#{images_host}/" << if m = /^(pv4|pfk|p7s|p6o|p3w|p7s|p)\/(.*)$/.match(@path)
    "p/" << m[2]
  else
    @path
  end
end
images_host() click to toggle source
# File lib/feeligo/stickers/sticker_image_tag.rb, line 62
def images_host
  return @opts[:host] if @opts[:host]
  if @opts[:scheme] == "https"
    "ssl.stkr.es"
  else
    "stkr.es"
  end
end
images_scheme() click to toggle source
# File lib/feeligo/stickers/sticker_image_tag.rb, line 57
def images_scheme
  @opts[:scheme] || "http"
end
tag_attributes() click to toggle source

Attributes of the <img> tag, as a Hash any options passed to initialize will be set as attributes of the <img> tag the “src” attribute will be set to the image_url

# File lib/feeligo/stickers/sticker_image_tag.rb, line 38
def tag_attributes
  attrs = {}
  @opts.each_pair{|k, v| attrs[k.to_s] = v.to_s}
  attrs["src"] = image_url
  attrs.reject{|k,v| %w(host scheme).include? k.to_s}
end
tag_attributes_string() click to toggle source

Attributes of the <img> tag, joined as a string

# File lib/feeligo/stickers/sticker_image_tag.rb, line 30
def tag_attributes_string
  tag_attributes.map{|k, v| "#{k}=\"#{v}\""}.join(' ')
end