Class: SmTranscript::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/sm_transcript/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



21
22
23
# File 'lib/sm_transcript/runner.rb', line 21

def initialize(argv)
  @options = Options.new(argv)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/sm_transcript/runner.rb', line 19

def options
  @options
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sm_transcript/runner.rb', line 25

def run
  # collect files to process
  begin
    # p "working directory is #{File.new(__FILE__).path}"
    # p "reading from #{@options.srcdir}"
    # p "writing to   #{@options.destdir}"
    raise "source directory doesn't exist" unless FileTest.exists?(@options.srcdir)
    raise "destination directory doesn't exist" unless FileTest.exists?(@options.destdir)
    
    # p "srctype is #{@options.srctype}"
    # process each file in srcdir whose extension is the same as srctype
    Dir.glob("#{@options.srcdir}/*.#{@options.srctype}") do |x|
      case @options.srctype.downcase
      when SmTranscript::Options::SEG_SRC_TYPE
        words = SmTranscript::SegReader.from_file(x).words
      when SmTranscript::Options::TTML_SRC_TYPE
        words = SmTranscript::TtmlReader.from_file(x).words
      when SmTranscript::Options::TXT_SRC_TYPE
        md = SmTranscript::MetadataReader.from_file(x).
      when SmTranscript::Options::SRT_SRC_TYPE
        words = SmTranscript::SrtReader.from_file(x).words
      else SmTranscript::Options::WRD_SRC_TYPE
        words = SmTranscript::WrdReader.from_file(x).words          
      end

      trans = SmTranscript::Transcript.new(words)
      meta  = SmTranscript::.new(md)
      destfile = File.basename( x, @options.srctype)

      case @options.desttype
      when SmTranscript::Options::HTML_DEST_TYPE
        raise "txt invalid srctype for html desttype" if @options.srctype == 
          SmTranscript::Options::TXT_SRC_TYPE
        destfile = "#{destfile}t1.html"
#            p "destfile is #{destfile}"
        trans.write_html("#{@options.destdir}/#{destfile}")
      when SmTranscript::Options::DATAJS_DEST_TYPE
        raise "txt is only valid srctype for datajs desttype" unless @options.srctype == 
          SmTranscript::Options::TXT_SRC_TYPE
        destfile = "#{destfile}data.js"
#            p "destfile is #{destfile}"
        meta.write_datajs("#{@options.destdir}/#{destfile}")
      else
        destfile = "#{destfile}t1.ttml"
#            p "destfile is #{destfile}"
        trans.write_ttml("#{@options.destdir}/#{destfile}")
      end 
    end  # Dir.glob()

    rescue SystemCallError => e
      STDERR.puts $!
    end
end