Class: SmTranscript::Metadata
- Inherits:
-
Object
- Object
- SmTranscript::Metadata
- Defined in:
- lib/sm_transcript/metadata.rb
Instance Method Summary collapse
-
#boilerplate ⇒ Object
write_datajs().
- #id_from_time ⇒ Object
-
#initialize(metadata) ⇒ Metadata
constructor
A new instance of Metadata.
-
#write_datajs(dest_file) ⇒ Object
While the format this method writes is JSON, it writes a data.js-like file for compatibility with the IIHS demo player.
Constructor Details
#initialize(metadata) ⇒ Metadata
Returns a new instance of Metadata.
13 14 15 |
# File 'lib/sm_transcript/metadata.rb', line 13 def initialize() @metadata = end |
Instance Method Details
#boilerplate ⇒ Object
write_datajs()
59 60 61 |
# File 'lib/sm_transcript/metadata.rb', line 59 def boilerplate() JSON end |
#id_from_time ⇒ Object
63 64 65 66 |
# File 'lib/sm_transcript/metadata.rb', line 63 def id_from_time() t = Time.now t.strftime("%y%m%d%H%M") end |
#write_datajs(dest_file) ⇒ Object
While the format this method writes is JSON, it writes a data.js-like file for compatibility with the IIHS demo player. There is also a write_json() method which will write a richer content set.
21 22 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 |
# File 'lib/sm_transcript/metadata.rb', line 21 def write_datajs(dest_file) # TODO: Do we want to notify user when overwriting existing file? # if File.exists?(dest_file) # p "overwriting existing destination file" # end return if @metadata.empty? id_val = @metadata['name'].chomp + "-#{id_from_time()}" unless @metadata['name'].nil? title_val = @metadata['title'].chomp unless @metadata['title'].nil? speaker_val = @metadata['speaker'].chomp unless @metadata['speaker'].nil? video_val = @metadata['video'].chomp unless @metadata['video'].nil? File.open(dest_file, "w") do |f| # f.puts 'var SMData = {' tmp = JSON.pretty_generate( { 'videos' => [ 'id' => id_val, 'title' => title_val, 'speaker' => speaker_val, 'video' => video_val, 'width' => 320, 'height' => 240, 'duration' => 523, 'preview' => 'preview.png', 'transcripts' => {'en-US' => 'transcript.trn'}, 'audio' => {'en-US' => '../audio/'}, 'defaultLocale' => 'en-US' ], 'locales' => {'en-US' => 'English (US)'} } ) # p tmp f.puts tmp f.flush end end |