Class: AnimateIt::Beats

Inherits:
Object
  • Object
show all
Defined in:
lib/animate_it/beats.rb

Instance Method Summary collapse

Constructor Details

#initialize(fps:) ⇒ Beats

Returns a new instance of Beats.



32
33
34
35
# File 'lib/animate_it/beats.rb', line 32

def initialize(fps:)
  @fps = fps
  @beats = {}
end

Instance Method Details

#[](name) ⇒ Object



51
52
53
# File 'lib/animate_it/beats.rb', line 51

def [](name)
  @beats[name.to_sym]
end

#add(name, at:, length:) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/animate_it/beats.rb', line 37

def add(name, at:, length:)
  @beats[name.to_sym] = Beat.new(
    name: name.to_sym,
    start_frame: AnimateIt::Units.frames(at, fps: @fps).to_i,
    duration_frames: AnimateIt::Units.frames(length, fps: @fps).to_i
  )
end

#allObject



55
56
57
# File 'lib/animate_it/beats.rb', line 55

def all
  @beats.values
end

#fetch(name) ⇒ Object



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

def fetch(name)
  @beats.fetch(name.to_sym) do
    raise Error, "Unknown beat: #{name.inspect}. Declared: #{@beats.keys.inspect}"
  end
end