Class: Keynote::Document

Inherits:
Object
  • Object
show all
Extended by:
Util
Includes:
Util
Defined in:
lib/keynote/document.rb

Defined Under Namespace

Classes: DocumentInvalid

Constant Summary collapse

DEFAULT_WIDTH =
1024
DEFAULT_HEIGHT =
768
WIDE_WIDTH =
1900
WIDE_HEIGHT =
1080

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

eval_script

Constructor Details

#initialize(arguments = {}) ⇒ Document

Returns a new instance of Document.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/keynote/document.rb', line 31

def initialize(arguments = {})
  @document_theme = arguments[:theme] || Theme.default
  @width = arguments.has_key?(:wide) && arguments[:wide] ? WIDE_WIDTH : DEFAULT_WIDTH
  @height = arguments.has_key?(:wide) && arguments[:wide] ? WIDE_HEIGHT : DEFAULT_HEIGHT
  @file_path = arguments[:file_path]
  @id = arguments[:id]
  @maximum_idle_duration = arguments[:maximumIdleDuration]
  @current_slide = arguments[:currentSlide]
  @slide_numbers_showing = arguments[:slideNumbersShowing]
  @auto_loop = arguments[:autoLoop]
  @auto_play = arguments[:autoPlay]
  @auto_restart = arguments[:autoRestart]
  @maximum_idle_duration = arguments[:maximumIdleDuration]
  @name = arguments[:name]
end

Instance Attribute Details

#auto_loopObject

Returns the value of attribute auto_loop.



8
9
10
# File 'lib/keynote/document.rb', line 8

def auto_loop
  @auto_loop
end

#auto_playObject

Returns the value of attribute auto_play.



8
9
10
# File 'lib/keynote/document.rb', line 8

def auto_play
  @auto_play
end

#auto_restartObject

Returns the value of attribute auto_restart.



8
9
10
# File 'lib/keynote/document.rb', line 8

def auto_restart
  @auto_restart
end

#current_slideObject

Returns the value of attribute current_slide.



8
9
10
# File 'lib/keynote/document.rb', line 8

def current_slide
  @current_slide
end

#document_themeObject

Returns the value of attribute document_theme.



8
9
10
# File 'lib/keynote/document.rb', line 8

def document_theme
  @document_theme
end

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/keynote/document.rb', line 8

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/keynote/document.rb', line 24

def id
  @id
end

#master_slidesObject

Returns the value of attribute master_slides.



8
9
10
# File 'lib/keynote/document.rb', line 8

def master_slides
  @master_slides
end

#maximum_idle_durationObject

Returns the value of attribute maximum_idle_duration.



8
9
10
# File 'lib/keynote/document.rb', line 8

def maximum_idle_duration
  @maximum_idle_duration
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/keynote/document.rb', line 8

def name
  @name
end

#slide_numbers_showingObject

Returns the value of attribute slide_numbers_showing.



8
9
10
# File 'lib/keynote/document.rb', line 8

def slide_numbers_showing
  @slide_numbers_showing
end

#slidesObject

Returns the value of attribute slides.



8
9
10
# File 'lib/keynote/document.rb', line 8

def slides
  @slides
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/keynote/document.rb', line 8

def width
  @width
end

Class Method Details

.allObject



149
150
151
# File 'lib/keynote/document.rb', line 149

def self.all
  self.find_with_conditions
end

.create(arguments = {}) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/keynote/document.rb', line 132

def self.create(arguments = {})
  theme = arguments[:theme] || Theme.default
  width = arguments[:wide] ? WIDE_WIDTH : DEFAULT_WIDTH
  height = arguments[:wide] ? WIDE_HEIGHT : DEFAULT_HEIGHT
  file_path = arguments[:file_path]

  result = eval_script <<-APPLE.unindent
    var Keynote = Application("Keynote")
    var theme = Keynote.themes.whose({ id: "#{theme.id}" }).first
    var doc = Keynote.Document({ documentTheme: theme, width: #{width}, height: #{height} });
    Keynote.documents.push(doc);
    JSON.stringify(doc.properties());
  APPLE

  self.new(symbolize_keys(result).merge(theme: theme, width: width, height: height, file_path: file_path))
end

.currentObject



165
166
167
# File 'lib/keynote/document.rb', line 165

def self.current
  self.all.first
end

.find_by(args) ⇒ Object

Raises:

  • (ArgumentError)


153
154
155
156
157
158
159
160
161
162
163
# File 'lib/keynote/document.rb', line 153

def self.find_by(args)
  raise ArgumentError.new('nil argument is given') unless args

  if args.is_a?(Hash) && args.has_key?(:id)
    conditions = ".whose({ id: '#{args[:id]}' })"
  else
    raise ArgumentError.new('Unsupported argument is given')
  end

  find_with_conditions(conditions)
end

Instance Method Details

#exportObject



128
129
130
# File 'lib/keynote/document.rb', line 128

def export
  # TBD
end

#saveObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/keynote/document.rb', line 108

def save
  return false unless @id
  return false unless @file_path
  eval_script <<-APPLE.unindent
    var Keynote = Application("Keynote")
    var doc = Keynote.documents.byId("#{@id}")
    var path = Path("#{@file_path}")
    doc.save({ in: path })
  APPLE
  true
rescue => e
  false
end

#save!Object

Raises:



124
125
126
# File 'lib/keynote/document.rb', line 124

def save!
  raise DocumentInvalid unless save
end