Class: Airplay::CLI::ImageViewer

Inherits:
Object
  • Object
show all
Defined in:
lib/airplay/cli/image_viewer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(devices, options = {}) ⇒ ImageViewer

Returns a new instance of ImageViewer.



6
7
8
9
# File 'lib/airplay/cli/image_viewer.rb', line 6

def initialize(devices, options = {})
  @devices = Array(devices)
  @options = options
end

Instance Attribute Details

#devicesObject (readonly)

Returns the value of attribute devices.



4
5
6
# File 'lib/airplay/cli/image_viewer.rb', line 4

def devices
  @devices
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/airplay/cli/image_viewer.rb', line 4

def options
  @options
end

Instance Method Details

#interactive(files) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/airplay/cli/image_viewer.rb', line 26

def interactive(files)
  numbers = Array(0...files.count)
  transition = "None"

  i = 0
  loop do
    view(files[i], transition)

    case read_char
    when "\e[C" # Right Arrow
      i = i + 1 > numbers.count - 1 ? 0 : i + 1
      transition = "SlideLeft"
    when "\e[D" # Left Arrow
      i = i - 1 < 0 ? numbers.count - 1 : i - 1
      transition = "SlideRight"
    else
      break
    end
  end
end

#slideshow(files) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/airplay/cli/image_viewer.rb', line 18

def slideshow(files)
  puts "Autoplay every #{options[:wait]}"
  files.each do |file|
    view(file)
    sleep options[:wait]
  end
end

#view(file, transition = "SlideLeft") ⇒ Object



11
12
13
14
15
16
# File 'lib/airplay/cli/image_viewer.rb', line 11

def view(file, transition = "SlideLeft")
  puts "Showing #{file}"
  devices.each do |device|
    device.view(file, transition: transition)
  end
end