Class: PlaySolder::Fake

Inherits:
Object
  • Object
show all
Defined in:
lib/play_solder/fake.rb

Direct Known Subclasses

Image, MP3, Swf

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Fake

Returns a new instance of Fake.



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



22
23
24
# File 'lib/play_solder/fake.rb', line 22

def path
  @path
end

Class Method Details

.for_path(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/play_solder/fake.rb', line 8

def self.for_path(path)
  ext = File.extname(path)
  
  if Image::EXTENSIONS.include?(ext)
    Image.new(path)
  elsif MP3::EXTENSIONS.include?(ext)
    MP3.new(path)
  elsif Swf::EXTENSIONS.include?(ext)
    Swf.new(path)
  else
    raise UnfakeablePathException.new("Can't fake #{ path }")
  end
end

Instance Method Details

#escaped_faked_fileObject



36
37
38
# File 'lib/play_solder/fake.rb', line 36

def escaped_faked_file
  @escaped_faked_file ||= faked_file.gsub("\"", "\\\"")
end

#extensionObject



28
29
30
# File 'lib/play_solder/fake.rb', line 28

def extension
  @extension = File.extname(path)
end

#faked_fileObject



40
41
42
43
44
45
46
47
# File 'lib/play_solder/fake.rb', line 40

def faked_file
  if @faked_file.nil?
    @faked_file = "/tmp/play_solder/#{ path }"
    parent = Pathname.new(@faked_file).parent.to_s
    FileUtils.mkdir_p(parent) unless File.exist?(parent)
  end
  @faked_file
end

#textObject



32
33
34
# File 'lib/play_solder/fake.rb', line 32

def text
  @text ||= File.basename(path).gsub(extension, "")
end