Class: Coradoc::Element::Video

Inherits:
Base
  • Object
show all
Extended by:
AttributeList::Matchers
Defined in:
lib/coradoc/element/video.rb

Constant Summary collapse

VALIDATORS_POSITIONAL =
[
  [:alt, String],
  [:width, Integer],
  [:height, Integer],
]
VALIDATORS_NAMED =
{
  title: String,
  poster: String,
  width: Integer,
  height: Integer,
  start: Integer,
  end: Integer,
  theme: one("dark", "light"),
  lang: /[a-z]{2,3}(?:-[A-Z]{2})?/,
  list: String,
  playlist: String,
  options: many("autoplay", "loop", "modest",
                "nocontrols", "nofullscreen", "muted"),
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeList::Matchers

many, one

Methods inherited from Base

#children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit

Constructor Details

#initialize(title, options = {}) ⇒ Video

Returns a new instance of Video.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/coradoc/element/video.rb', line 8

def initialize(title, options = {})
  @title = title
  @id = options.fetch(:id, nil)
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
  @src = options.fetch(:src, "")
  @attributes = options.fetch(:attributes, AttributeList.new)
  if @attributes.any?
    @attributes.validate_positional(VALIDATORS_POSITIONAL)
    @attributes.validate_named(VALIDATORS_NAMED)
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/coradoc/element/video.rb', line 4

def id
  @id
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/coradoc/element/video.rb', line 4

def options
  @options
end

#srcObject

Returns the value of attribute src.



4
5
6
# File 'lib/coradoc/element/video.rb', line 4

def src
  @src
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/coradoc/element/video.rb', line 4

def title
  @title
end

Instance Method Details

#to_adocObject



20
21
22
23
24
25
# File 'lib/coradoc/element/video.rb', line 20

def to_adoc
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
  title = ".#{@title}\n" unless @title.empty?
  attrs = @attributes.to_adoc
  [anchor, title, "video::", @src, attrs].join("")
end