Class: GuidedPath::MultimediaNode

Inherits:
Node
  • Object
show all
Defined in:
lib/guided_path/multimedia_node.rb

Constant Summary collapse

CATEGORIES =
%w{image youtube}

Instance Attribute Summary collapse

Attributes inherited from Node

#label, #next_node

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ MultimediaNode

Returns a new instance of MultimediaNode.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/guided_path/multimedia_node.rb', line 10

def initialize(args = {})
  super
  args = args.symbolize_keys

  raise(ArgumentError, "Must specify a value for the node") unless args[:url]
  @url = args[:url].to_s

  raise(ArgumentError, "Must specify a source") unless args[:url]
  @source = args[:source].to_s
  raise(ArgumentError, "Must specify a source in #{CATEGORIES.join(', ')}") unless CATEGORIES.include?(@source)
  @caption = args[:caption]  
  if @caption.kind_of?(String)
    @caption = {text: @caption, position: 'bottom'}
  elsif @caption.kind_of?(Hash)
    @caption = {text: @caption['text'], position: @caption['position'] || 'top'}
  end
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



8
9
10
# File 'lib/guided_path/multimedia_node.rb', line 8

def caption
  @caption
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/guided_path/multimedia_node.rb', line 8

def source
  @source
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/guided_path/multimedia_node.rb', line 8

def url
  @url
end

Instance Method Details

#to_hashObject



29
30
31
32
33
34
35
# File 'lib/guided_path/multimedia_node.rb', line 29

def to_hash
  output = super
  output[:type] = @source 
  output[:url] = @url
  output[:caption] = @caption
  output
end