class Qwik::SmilGenerator

Public Class Methods

new() click to toggle source
# File vendor/qwik/lib/qwik/act-smil.rb, line 81
def initialize
  @width, @height = 320, 240
  @time_table = []
end

Public Instance Methods

generate_html() click to toggle source
# File vendor/qwik/lib/qwik/act-smil.rb, line 137
def generate_html
  table = [:table]
  table << [:tr,
    [:th, 'IN'],
    [:th, 'OUT'],
    [:th, 'MSG']
  ]
  @time_table.each {|url, time_begin, time_end, title|
    table << [:tr, 
      [:td, time_begin.to_smil],
      [:td, time_end.to_smil],
      [:td, title]]
  }
  return table
end
generate_smil() click to toggle source
# File vendor/qwik/lib/qwik/act-smil.rb, line 117
def generate_smil
  time = 0.0
  par = []
  @time_table.each {|url, time_begin, time_end, title|
    duration = time_end.to_f - time_begin.to_f
    par << [:video, {:region=>'v', :begin=>"#{time}s",
        :src=>url, :'clip-begin'=>time_begin.to_smil,
        :'clip-end'=>time_end.to_smil}]
    time += duration
  }
  smil = [:smil, {:xmlns=>'http://www.w3.org/2001/SMIL20/Language',
      :'xmlns:rn'=>'http://features.real.com/2001/SMIL20/Extensions'},
    [:head,
      [:layout,
        [:'root-layout', {:width=>@width, :height=>@height}],
        [:region, {:id=>'v', :fit=>'meet'}]]],
    [:body, [:par, *par]]]
  return smil
end
parse(str) click to toggle source
# File vendor/qwik/lib/qwik/act-smil.rb, line 86
def parse(str)
  url = nil
  @width, @height = 320, 240
  @time_table = []
  tokens = tokenize(str)
  tokens.each {|token|
    case token[0]
    when :dl
      case token[1]
      when 'url'    then url     = token[2]
      when 'width'  then @width  = token[2]
      when 'height' then @height = token[2]
      else
        raise 'unknown param type'
      end
    when :table
      time_begin = SmilTime.at_smil(token[1])
      time_end   = SmilTime.at_smil(token[2])
      title = token[3]
      @time_table << [url, time_begin, time_end, title]
    else
      raise 'unknown type'
    end
  }
  return [@width, @height, @time_table] # only for test
end
tokenize(str) click to toggle source
# File vendor/qwik/lib/qwik/act-smil.rb, line 113
def tokenize(str)
  return TextTokenizer.tokenize(str)
end