Class: Vtt2An::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/vtt2an/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webvtt) ⇒ Converter

Returns a new instance of Converter.



10
11
12
# File 'lib/vtt2an/converter.rb', line 10

def initialize(webvtt)
  @webvtt = webvtt
end

Instance Attribute Details

#webvttObject

Returns the value of attribute webvtt.



8
9
10
# File 'lib/vtt2an/converter.rb', line 8

def webvtt
  @webvtt
end

Instance Method Details

#convertObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vtt2an/converter.rb', line 14

def convert
  
  output = REXML::Document.new
  an = output.add_element("akomaNtoso")
  debate = an.add_element("debate")
  meta = debate.add_element("meta")
  references = meta.add_element("references")
        
  webvtt.speakers.each do |speaker|
    references.add_element("TLCPerson", 
      "href" => "", 
      "id" => speaker.parameterize,
      "showAs" => speaker
    )
  end

  body = debate.add_element("debateBody")
  section = body.add_element("debateSection")
  heading = section.add_element("heading")
  heading.add_text "Title"

  webvtt.merged_cues.each do |cue|
    speech = section.add_element("speech",
      "by" => "##{cue.speaker.parameterize}"
    )
    p = speech.add_element("p")
    p.add_text cue.text
  end

  output
end