Class: EmbebbedFile::Type
- Inherits:
-
Object
- Object
- EmbebbedFile::Type
- Defined in:
- lib/asker/loader/embedded_file/type.rb
Instance Method Summary collapse
- #for(value, localdir) ⇒ Object
- #is_audio?(filename) ⇒ Boolean
- #is_image?(filename) ⇒ Boolean
- #is_url?(value) ⇒ Boolean
- #is_video?(filename) ⇒ Boolean
Instance Method Details
#for(value, localdir) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/asker/loader/embedded_file/type.rb', line 4 def for(value, localdir) if is_url? value return :image_url if is_image? value return :audio_url if is_audio? value return :video_url if is_video? value Logger.error "EmbebbedFile::Type.for: Unknown URL type (#{value})" exit 1 end filepath = File.join(localdir, value) unless File.exist?(filepath) Logger.error "EmbeddedFile::Type.for: File does not exist (#{filepath})" exit 1 end return :image if is_image? value return :audio if is_audio? value return :video if is_video? value :text end |
#is_audio?(filename) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/asker/loader/embedded_file/type.rb', line 27 def is_audio?(filename) extens = [".mp3", ".ogg", ".wav"] extens.each { |ext| return true if filename.downcase.end_with?(ext) } false end |
#is_image?(filename) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/asker/loader/embedded_file/type.rb', line 33 def is_image?(filename) extens = [".jpg", ".jpeg", ".png"] extens.each { |ext| return true if filename.downcase.end_with?(ext) } false end |
#is_url?(value) ⇒ Boolean
45 46 47 48 49 |
# File 'lib/asker/loader/embedded_file/type.rb', line 45 def is_url?(value) return true if value.start_with?("https://", "http://") false end |
#is_video?(filename) ⇒ Boolean
39 40 41 42 43 |
# File 'lib/asker/loader/embedded_file/type.rb', line 39 def is_video?(filename) extens = [".mp4", ".ogv"] extens.each { |ext| return true if filename.downcase.end_with?(ext) } false end |