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.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/sm_transcript/runner.rb', line 17

def options
  @options
end

Instance Method Details

#runObject



23
24
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
# File 'lib/sm_transcript/runner.rb', line 23

def run
  # collect files to process
  begin
    raise "source directory doesn't exist" unless FileTest.exists?(@options.srcdir)
    raise "destination directory doesn't exist" unless FileTest.exists?(@options.destdir)
    
    # process each file in srcdir whose extension is the same as srctype
    Dir.glob("#{@options.srcdir}/*.#{@options.srctype}") do |x|

      case @options.srctype
      when SmTranscript::Options::SEG_SRC_TYPE
        words = SmTranscript::SegReader.from_file(x).words
      when SmTranscript::Options::TXT_SRC_TYPE
        md = SmTranscript::MetadataReader.from_file(x).
      else SmTranscript::Options::WRD_SRC_TYPE
        words = SmTranscript::WrdReader.from_file(x).words          
      end

      trans = SmTranscript::Transcript.new(words)
      meta  = SmTranscript::Metadata.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