Class: Riddler::Elements::Link

Inherits:
Riddler::Element show all
Defined in:
lib/riddler/elements/link.rb

Instance Attribute Summary

Attributes inherited from Riddler::Element

#context, #definition

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Riddler::Element

for, inherited, #initialize, subclasses

Methods included from Includeable

#include?, #include_predicate

Constructor Details

This class inherits a constructor from Riddler::Element

Class Method Details

.typeObject



4
5
6
# File 'lib/riddler/elements/link.rb', line 4

def self.type
  "link"
end

Instance Method Details

#hrefObject



8
9
10
# File 'lib/riddler/elements/link.rb', line 8

def href
  @href ||= context.render definition["href"]
end


12
13
14
15
16
17
18
19
# File 'lib/riddler/elements/link.rb', line 12

def link
  return href if context.variable(:interaction).nil?
  "/interactions/%s/redirect?element_id=%s&url=%s" % [
    context.interaction.id,
    definition["id"],
    href
  ]
end

#textObject



21
22
23
# File 'lib/riddler/elements/link.rb', line 21

def text
  context.render definition["text"]
end

#to_hashObject



25
26
27
# File 'lib/riddler/elements/link.rb', line 25

def to_hash
  super.merge text: text, href: href, link: link
end