Class: FunCi::Tui::Animation

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_ci/tui/animation.rb

Constant Summary collapse

TYPES =
{
  failure: { total_frames: 40, priority: 3 },
  timeout: { total_frames: 4, priority: 2 },
  success: { total_frames: 40, priority: 1 },
  stage_pass: { total_frames: 3, priority: 0 }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, run_id:, stage: nil) ⇒ Animation

Returns a new instance of Animation.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/fun_ci/tui/animation.rb', line 15

def initialize(type:, run_id:, stage: nil)
  raise ArgumentError, "Unknown animation type: #{type}" unless TYPES.key?(type)

  @type = type
  @run_id = run_id
  @stage = stage
  @frame = 0
end

Instance Attribute Details

#frameObject (readonly)

Returns the value of attribute frame.



13
14
15
# File 'lib/fun_ci/tui/animation.rb', line 13

def frame
  @frame
end

#run_idObject (readonly)

Returns the value of attribute run_id.



13
14
15
# File 'lib/fun_ci/tui/animation.rb', line 13

def run_id
  @run_id
end

#stageObject (readonly)

Returns the value of attribute stage.



13
14
15
# File 'lib/fun_ci/tui/animation.rb', line 13

def stage
  @stage
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/fun_ci/tui/animation.rb', line 13

def type
  @type
end

Instance Method Details

#advance!Object



24
25
26
# File 'lib/fun_ci/tui/animation.rb', line 24

def advance!
  @frame += 1
end

#finished?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/fun_ci/tui/animation.rb', line 28

def finished?
  frame >= total_frames
end

#has_footer?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fun_ci/tui/animation.rb', line 44

def has_footer?
  %i[failure success].include?(@type)
end

#has_header?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fun_ci/tui/animation.rb', line 40

def has_header?
  %i[failure timeout success].include?(@type)
end

#priorityObject



36
37
38
# File 'lib/fun_ci/tui/animation.rb', line 36

def priority
  TYPES[@type][:priority]
end

#total_framesObject



32
33
34
# File 'lib/fun_ci/tui/animation.rb', line 32

def total_frames
  TYPES[@type][:total_frames]
end