Module: Klear::AnimationOrder

Extended by:
AnimationOrder
Included in:
AnimationOrder
Defined in:
lib/klear/animation_order.rb

Instance Method Summary collapse

Instance Method Details

#frame_number_from_string(filename) ⇒ Object



19
20
21
22
23
# File 'lib/klear/animation_order.rb', line 19

def frame_number_from_string(filename)
  Integer(filename.tr('^0-9', '').sub(/^0+(\d)/, '\1'))
rescue ArgumentError => e
  raise e, "no frame number in filename: '#{filename}' - #{e}"
end

#glob(pattern, &blk) ⇒ Object



3
4
5
6
7
# File 'lib/klear/animation_order.rb', line 3

def glob pattern, &blk
  filenames = sort(Dir.glob(pattern))
  blk.nil? or filenames.each {|fname| blk.call(fname)}
  filenames
end

#sort(filenames) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/klear/animation_order.rb', line 9

def sort(filenames)
  filenames.sort do |a, b| 
    begin
      frame_number_from_string(a) <=> frame_number_from_string(b)
    rescue ArgumentError => e
      a <=> b
    end
  end
end