Class: Coradoc::Input::Html::Converters::Audio

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/html/input/converters/audio.rb

Instance Method Summary collapse

Methods inherited from Base

#convert, #escape_text, #extract_leading_trailing_whitespace, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#extract_title(node) ⇒ Object



31
32
33
34
35
36
# File 'lib/coradoc/html/input/converters/audio.rb', line 31

def extract_title(node)
  title = node.at('./track') || node.at('.//source')
  return '' if title.nil?

  title['label'] || title['srclang'] || ''
end

#options(node) ⇒ Object



38
39
40
41
42
43
# File 'lib/coradoc/html/input/converters/audio.rb', line 38

def options(node)
  autoplay = node['autoplay']
  loop_attr = node['loop']
  controls = node['controls']
  [autoplay, loop_attr, controls].compact
end

#to_coradoc(node, _state = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/coradoc/html/input/converters/audio.rb', line 8

def to_coradoc(node, _state = {})
  src = node['src']
  id = node['id']
  title = extract_title(node)
  options(node)

  # Use Block with custom attributes to store audio info
  # CoreModel doesn't have a specific Audio type, so we use Block
  # with element_attributes to store audio-specific data
  Coradoc::CoreModel::Block.new(
    element_type: 'audio',
    block_semantic_type: :audio,
    content: src,
    title: title,
    id: id,
    element_attributes: {
      autoplay: node['autoplay'],
      loop: node['loop'],
      controls: node['controls']
    }.compact
  )
end