Class: Typingpool::Filer::Files

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Utility::Castable
Defined in:
lib/typingpool/filer/files.rb,
lib/typingpool/filer/files/audio.rb

Overview

Handler for collection of Filer instances. Makes them enumerable, Allows easy re-casting to Filer::Files subclasses, and provides various other convenience methods.

Direct Known Subclasses

Dir, Audio

Defined Under Namespace

Classes: Audio

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility::Castable

included

Constructor Details

#initialize(files) ⇒ Files

Constructor. Takes array of Filer instances.



17
18
19
# File 'lib/typingpool/filer/files.rb', line 17

def initialize(files)
  @files = files
end

Instance Attribute Details

#filesObject (readonly)

Array of Filer instances included in the collection



14
15
16
# File 'lib/typingpool/filer/files.rb', line 14

def files
  @files
end

Instance Method Details

#as(sym) ⇒ Object

Cast this collection into a new Filer::Files subtype, e.g. Filer::Files::Audio.

Params

sym

Symbol corresponding to Filer::Files subclass to cast

into. For example, passing :audio will cast into a Filer::Files::Audio.

Returns

Instance of new Filer::Files subclass



36
37
38
39
# File 'lib/typingpool/filer/files.rb', line 36

def as(sym)
  #super calls into Utility::Castable mixin
  super(sym, files)
end

#eachObject

Enumerate through Filer instances.



22
23
24
25
26
# File 'lib/typingpool/filer/files.rb', line 22

def each
  files.each do |file|
    yield file
  end
end

#mv!(to) ⇒ Object

Calls mv! on each Filer instance in the collection. See documentation for Filer#mv! for definition of “to” param and for return value.



50
51
52
# File 'lib/typingpool/filer/files.rb', line 50

def mv!(to)
  files.map{|file| file.mv! to }
end

#to_streamsObject

Returns array of IO streams created by calling to_stream on each Filer instance in the collection.



43
44
45
# File 'lib/typingpool/filer/files.rb', line 43

def to_streams
  self.map{|file| file.to_stream }
end