Class: Anki::Media
- Inherits:
-
Object
- Object
- Anki::Media
- Defined in:
- lib/ankirb/util/media.rb
Class Method Summary collapse
Class Method Details
.process(filepath, str) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ankirb/util/media.rb', line 5 def self.process filepath, str media = MimeMagic.by_magic(File.open(filepath)) case when media.image? tag = %(<img src="#{File.basename(filepath)}"/>) if str.match(/{{img}}/) str.sub!(/{{img}}/, tag) else str << tag unless str.include? tag end when media.audio?, media.video? #video also has a sound tag, idk tag = "[sound:#{File.basename(filepath)}]" str << tag unless str.include? tag else raise "Unknown media type - #{filepath}" end end |
.valid_media?(filepath) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ankirb/util/media.rb', line 24 def self.valid_media? filepath return false unless File.exists?(filepath) media = MimeMagic.by_magic(File.open(filepath)) if media.image? or media.video? or media.audio? true else false end end |