keynote_driver 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'keynote_driver'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ optparser = OptionParser.new do |opts|
10
+ opts.banner = 'Usage: keynote_driver [options]'
11
+
12
+ opts.separator ''
13
+ opts.separator 'File options:'
14
+
15
+ opts.on('-p', '--pres PRESENTATION', String, 'Presentation path') do |pres_path|
16
+ options[:pres] = pres_path
17
+ end
18
+
19
+ opts.on('-t', '--time TIMECODES', String, 'Time codes file path') do |tc_path|
20
+ options[:tc_path] = tc_path
21
+ end
22
+
23
+ opts.on('-h', '--help', 'Show this message') do |v|
24
+ puts opts; exit
25
+ end
26
+
27
+ opts.on('-v', '--version', 'Show version') do |v|
28
+ puts KeynoteDriver::VERSION; exit
29
+ end
30
+ end
31
+
32
+ optparser.parse!
33
+
34
+ unless options[:pres] || options[:tc_path]
35
+ puts optparser
36
+ exit
37
+ end
38
+
39
+ KeynoteDriver.launch!(options[:pres], options[:tc_path])
@@ -0,0 +1,21 @@
1
+ require 'appscript'
2
+
3
+ require "keynote_driver/version"
4
+ require "keynote_driver/presentation"
5
+ require "keynote_driver/time_code"
6
+
7
+ module KeynoteDriver
8
+ extend self
9
+
10
+ def launch!(pres_path, timecode_path)
11
+ begin
12
+ delays = TimeCode.new(timecode_path).deltas
13
+ pres = Presentation.new(pres_path)
14
+ pres.exec(delays)
15
+ rescue TimeCodeException => ex
16
+ puts "Time code file: #{ex}"
17
+ rescue PresentationException => ex
18
+ puts "Presentation: #{ex}"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ module KeynoteDriver
2
+ class PresentationException < Exception; end
3
+
4
+ class Presentation
5
+ def initialize(path)
6
+ if not File.exists?(path)
7
+ raise PresentationException.new("#{path} doesn't exists.")
8
+ end
9
+
10
+ @path = path
11
+ end
12
+
13
+ def load_file_in_keynote
14
+ @system = find_system
15
+ @app = find_keynote
16
+ @app.launch
17
+ @app.open(@path)
18
+ end
19
+
20
+ def exec(delays)
21
+ load_file_in_keynote
22
+
23
+ begin
24
+ @system.processes['Keynote'].menu_bars[1].menu_bar_items[10].menus.menu_items[3].click
25
+ rescue Appscript::CommandError
26
+ retry
27
+ end
28
+
29
+ delays.each do |delay|
30
+ Kernel.sleep(delay)
31
+ @app.show_next
32
+ end
33
+
34
+ @app.stop_slideshow
35
+ end
36
+
37
+ private
38
+
39
+ def find_keynote
40
+ Appscript.app('Keynote.app')
41
+ end
42
+
43
+ def find_system
44
+ Appscript.app('System Events')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ module KeynoteDriver
2
+ class TimeCodeException < Exception; end
3
+
4
+ class TimeCode
5
+ attr_reader :timecodes
6
+
7
+ def initialize(timecode_path)
8
+ if not File.exists?(timecode_path)
9
+ raise TimeCodeException.new "#{timecode_path} doesn't exists."
10
+ end
11
+
12
+ @timecodes = process(File.read(timecode_path))
13
+ end
14
+
15
+ def process(timecode)
16
+ lines = timecode.split("\r")
17
+ codes = lines.map{ |l| l.split("\t")[1] }
18
+
19
+ out = codes.map{ |c| c.to_f.round(3) }
20
+
21
+ # Check if are not incremental
22
+ if out.sort != out
23
+ raise TimeCodeException.new('Time codes must be incremental.')
24
+ end
25
+
26
+ out
27
+ end
28
+
29
+ def deltas
30
+ timecodes.each_with_index.map do |t, i|
31
+ if i == 0
32
+ t
33
+ else
34
+ t - timecodes[i - 1]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module KeynoteDriver
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keynote_driver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Federico Ravasio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rb-appscript
16
+ requirement: &70127599196720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70127599196720
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70127599196300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70127599196300
36
+ description: bbbb
37
+ email:
38
+ - ravasio.federico@gmail.com
39
+ executables:
40
+ - keynote_driver
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - lib/keynote_driver/presentation.rb
45
+ - lib/keynote_driver/time_code.rb
46
+ - lib/keynote_driver/version.rb
47
+ - lib/keynote_driver.rb
48
+ - bin/keynote_driver
49
+ homepage: https://github.com/razielgn/keynote_driver
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: keynote_driver
69
+ rubygems_version: 1.8.11
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: bla
73
+ test_files: []
74
+ has_rdoc: