Class: Swaf

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/swaf.rb,
lib/swaf/version.rb

Constant Summary collapse

VERSION =
[
	major = 0,
	minor = 1,
	patch = 0,
].join('.')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSwaf

Returns a new instance of Swaf.



29
30
31
32
# File 'lib/swaf.rb', line 29

def initialize
	@dumper = SwfRuby::SwfDumper.new
	@tamperer = SwfRuby::SwfTamperer.new
end

Instance Attribute Details

#dumperObject (readonly)

Returns the value of attribute dumper.



24
25
26
# File 'lib/swaf.rb', line 24

def dumper
  @dumper
end

Class Method Details

.load(doc) ⇒ Object



12
13
14
15
# File 'lib/swaf.rb', line 12

def self.load(doc)
	(swaf = self.new).load!(doc)
	swaf
end

.load_file(filename) ⇒ Object



17
18
19
20
21
22
# File 'lib/swaf.rb', line 17

def self.load_file(filename)
	(swaf = self.new).load!(
		File.binread(filename)
	)
	swaf
end

Instance Method Details

#detect(id) ⇒ Object Also known as: find



38
39
40
41
42
# File 'lib/swaf.rb', line 38

def detect(id)
	if t = @dumper.tags.each_with_index.find {|t, i| t.character_id == id }
		@dumper.tags_addresses[t[1]]
	end
end

#load!(swf) ⇒ Object



34
35
36
# File 'lib/swaf.rb', line 34

def load!(swf)
	self.dumper.dump(swf)
end

#replace(params = {}) ⇒ Object



45
46
47
48
49
# File 'lib/swaf.rb', line 45

def replace(params={})
	self.class.load(@tamperer.replace(@dumper.swf, params.inject([]) {|targets, (k, v)|
		targets << make_target(k, v)
	}))
end