Class: SmTranscript::Runner
- Inherits:
-
Object
- Object
- SmTranscript::Runner
- Defined in:
- lib/sm_transcript/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/sm_transcript/runner.rb', line 17 def @options end |
Instance Method Details
#run ⇒ Object
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) = 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}" .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 |