Class: FlashTool::FlashTool
- Inherits:
-
Object
- Object
- FlashTool::FlashTool
- Defined in:
- lib/flash_tool.rb
Overview
This class provides usefull utilities for getting informations from flash files
Important
Method FlashTool.text and options FlashTool.method_missing(“text”, “file”) and swfdump(“file”,“text”) on same system don’t work appropriate instead use method parse_text
Class Method Summary collapse
-
.flash_info(file) ⇒ Object
Returns hash value with basic flash parameters Keys are [width, rate, height, frames] and values are kind of string.
-
.method_missing(option, file) ⇒ Object
Call swfdump commands in shorter way Can be used any option from swfdump command in casess: width, heihght and frames returns Integer in case rate returns Float in all other casess retruns String.
-
.parse_text(file) ⇒ Object
This method parse text from swf file.
-
.swfdump(file, option = nil) ⇒ Object
This method is very similar to swfdump command www.swftools.org/swfdump.html Use longer options for this commands without – DON’T use option text that option don’t work ===Examples FlashTool.swfdump(‘test.swf’, ‘rate’).
Class Method Details
.flash_info(file) ⇒ Object
Returns hash value with basic flash parameters Keys are [width, rate, height, frames] and values are kind of string
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flash_tool.rb', line 57 def flash_info(file) args = ['width', 'rate', 'height', 'frames'] data = swfdump(file, args) data.gsub!(/(-X)/, "width ") data.gsub!(/(-Y)/, "height ") data.gsub!(/(-r)/, "rate ") data.gsub!(/(-f)/, "frames ") return Hash[*data.split(' ')] end |
.method_missing(option, file) ⇒ Object
Call swfdump commands in shorter way Can be used any option from swfdump command in casess: width, heihght and frames returns Integer in case rate returns Float in all other casess retruns String
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/flash_tool.rb', line 41 def method_missing(option, file) text = self.swfdump(file, option) option = option.to_s if option == "width" || option == 'height' || option == 'frames' return text.split(' ').last.to_i elsif option == 'rate' return text.split(' ').last.to_f else return text end end |
.parse_text(file) ⇒ Object
This method parse text from swf file. File must have extension swf
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flash_tool.rb', line 20 def parse_text(file) # something is bad with this program don't send errors, and we must check for errors # we must check file first # by documetation swfdump --text need to do this but raise FlashToolError, "File missing path: #{file}" unless File.exist?(file) raise FlashToolError, "Wrong file type SWF path: #{file} " unless file =~ /(.swf)$/i command = "swfstrings #{file}" output = `#{command} 2>&1` # if file have appropiate name but is something is wrong with him raise FlashToolError, output if output =~/(errors.)$/ return output end |
.swfdump(file, option = nil) ⇒ Object
This method is very similar to swfdump command www.swftools.org/swfdump.html Use longer options for this commands without – DON’T use option text that option don’t work
Examples
FlashTool.swfdump('test.swf', 'rate')
FlashTool.swfdump('test.swf', ['rate','width','height'])
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/flash_tool.rb', line 78 def swfdump(file, option=nil) command = 'swfdump' if option if option.kind_of? Array option.collect! { |a| "--#{a}" } option = option.join(' ') else option = "--#{option}" end end command = "#{command} #{option} #{file}" output = `#{command} 2>&1` if $?.exitstatus != 0 raise FlashToolError, "SWF command : #{command.inspect} failed : #{{:status_code => $?, :output => output}.inspect}" else return output end end |