Class: Slide

Inherits:
Object
  • Object
show all
Defined in:
lib/soby/slide.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Slide

Returns a new instance of Slide.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/soby/slide.rb', line 11

def initialize (element)

  attr = element.attributes

  ## Zoom & Path -> not used...
  # @transition_path_hide = attr["transition-path-hide"].value
  # @transition_zoom_percent = attr["transition-zoom-percent"].value

  #Not always set ! We use the title instead
  #    @id = attr["id"].value

  @transition_profile = attr["transition-profile"].value
  @transition_duration_ms = attr["transition-duration-ms"].value.to_f
  @timeout_ms = attr["timeout-ms"].value.to_f
  @timeout_enable = attr["timeout-enable"].value  == "true"
  #    @show_in_frame_list = attr["show-in-frame-list"].value

  @clip = attr["clip"].value
  @hide = attr["hide"].value == "true"
  @sequence = attr["sequence"].value.to_i
  @title = attr["title"].value
  @refid = attr["refid"].value

  init_transition_profile

  @videos = []
  @animations = []
  @current_animation = 0
end

Instance Attribute Details

#animationsObject (readonly)

Returns the value of attribute animations.



8
9
10
# File 'lib/soby/slide.rb', line 8

def animations
  @animations
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/soby/slide.rb', line 3

def description
  @description
end

#heightObject (readonly)

Returns the value of attribute height.



4
5
6
# File 'lib/soby/slide.rb', line 4

def height
  @height
end

#hideObject

Returns the value of attribute hide.



3
4
5
# File 'lib/soby/slide.rb', line 3

def hide
  @hide
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/soby/slide.rb', line 4

def id
  @id
end

#matrixObject

Returns the value of attribute matrix.



3
4
5
# File 'lib/soby/slide.rb', line 3

def matrix
  @matrix
end

#nextObject

Returns the value of attribute next.



3
4
5
# File 'lib/soby/slide.rb', line 3

def next
  @next
end

#previousObject

Returns the value of attribute previous.



3
4
5
# File 'lib/soby/slide.rb', line 3

def previous
  @previous
end

#refidObject

Returns the value of attribute refid.



3
4
5
# File 'lib/soby/slide.rb', line 3

def refid
  @refid
end

#sequenceObject

Returns the value of attribute sequence.



3
4
5
# File 'lib/soby/slide.rb', line 3

def sequence
  @sequence
end

#timeout_enableObject (readonly)

transition states



7
8
9
# File 'lib/soby/slide.rb', line 7

def timeout_enable
  @timeout_enable
end

#timeout_msObject (readonly)

transition states



7
8
9
# File 'lib/soby/slide.rb', line 7

def timeout_ms
  @timeout_ms
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/soby/slide.rb', line 4

def title
  @title
end

#transformObject (readonly)

Returns the value of attribute transform.



4
5
6
# File 'lib/soby/slide.rb', line 4

def transform
  @transform
end

#transition_duration_msObject (readonly)

transition states



7
8
9
# File 'lib/soby/slide.rb', line 7

def transition_duration_ms
  @transition_duration_ms
end

#transition_profileObject (readonly)

transition states



7
8
9
# File 'lib/soby/slide.rb', line 7

def transition_profile
  @transition_profile
end

#videosObject (readonly)

Returns the value of attribute videos.



8
9
10
# File 'lib/soby/slide.rb', line 8

def videos
  @videos
end

#widthObject (readonly)

Returns the value of attribute width.



4
5
6
# File 'lib/soby/slide.rb', line 4

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



4
5
6
# File 'lib/soby/slide.rb', line 4

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



4
5
6
# File 'lib/soby/slide.rb', line 4

def y
  @y
end

Instance Method Details

#add_animation(id, animation) ⇒ Object



92
93
94
# File 'lib/soby/slide.rb', line 92

def add_animation (id, animation) 
  @animations[id] = animation
end

#add_video(video) ⇒ Object



83
84
85
# File 'lib/soby/slide.rb', line 83

def add_video (video)
  @videos << video
end

#has_next_animation?Boolean

Returns:

  • (Boolean)


96
97
98
99
# File 'lib/soby/slide.rb', line 96

def has_next_animation?() 
  return false if @animations.size == 0 
  return @current_animation < @animations.size
end

#has_previous_animation?Boolean

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/soby/slide.rb', line 106

def has_previous_animation?() 
  return false if @animations.size == 0 
  return @current_animation > 0
end

#has_videos?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/soby/slide.rb', line 87

def has_videos?() 
  @videos.size() != 0 
end

#init_transition_profileObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/soby/slide.rb', line 46

def init_transition_profile
  case @transition_profile
  when "linear" 
    @transition = Proc.new { |x| x } 
  when "accelerate" 
    @transition = Proc.new { |x| x**3 } 
  when "strong-accelerate"
    @transition = Proc.new { |x| x**5 } 
  when "decelerate" 
    @transition = Proc.new { |x| 1 - ((1 - x) ** 3) } 
  when "strong-decelerate" 
    @transition = Proc.new { |x| 1 - ((1 - x) ** 5) } 
  when "accelerate-decelerate" 
    @transition = Proc.new { |x|   
      xs = x <= 0.5 ? x : 1 - x
      y = ((2 * xs) ** 3) / 2
      x <= 0.5 ? y : 1 - y
    }
  when "strong-decelerate-accelerate"
    @transition = Proc.new { |x| 
      xs = x <= 0.5 ? x : 1 - x
      y = ((2 * xs) **  5) / 2
      x <= 0.5 ? y : 1 - y 
    }
  when  "immediate-beginning"
    @transition = Proc.new { |x| 1 }
  when  "immediate-end"
    @transition = Proc.new { |x| x === 1 ? 1 : 0}
  when "immediate-middle" 
    @transition = Proc.new { |x| x >= 0.5 ? 1 : 0}
    
  else 
    @transition = Proc.new {|x| x }
  end
end

#is_hidden?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/soby/slide.rb', line 41

def is_hidden?
   @hide
end

#next_animationObject



101
102
103
104
# File 'lib/soby/slide.rb', line 101

def next_animation 
  @current_animation = @current_animation + 1
  @animations[@current_animation - 1]
end

#previous_animationObject



111
112
113
114
# File 'lib/soby/slide.rb', line 111

def previous_animation 
  @current_animation = @current_animation - 1
  @animations[@current_animation]
end

#set_geometry(element, matrix) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/soby/slide.rb', line 117

def set_geometry (element, matrix)

  @matrix = matrix
  attr = element.attributes

  #    @label = attr["label"].value
  #    @id = attr["id"].value
  @x = attr["x"].value.to_f
  @y = attr["y"].value.to_f
  @width = attr["width"].value.to_f
  @height = attr["height"].value.to_f
  
  @description = element.css("desc").text if element.css("desc").size > 0
  @title = element.css("title").text if element.css("title").size > 0

  ## TODO : check if title != animation and video 

  # Animation & Video are not ruby Code !
  if @title != nil 
    if  @title.match(/animation/) or @title.match(/video/) 
      @description = nil
    end
  end
  
  #eval @description if @description
end

#to_sObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/soby/slide.rb', line 149

def to_s 
  ["id ",@id.to_s ," ",
   "transition_path_hide ",@transition_path_hide.to_s ," ",
   "transition_profile ",@transition_profile.to_s ," ",
   "transition_zoom_percent ",@transition_zoom_percent.to_s ," ",
   "transition_duration_ms ",@transition_duration_ms.to_s ," ",
   "timeout_ms ",@timeout_ms.to_s ," ",
   "timeout_enable ",@timeout_enable.to_s ," ",
   "show_in_frame_list ",@show_in_frame_list.to_s ," ",
   "clip ",@clip.to_s ," ",
   "hide ",@hide.to_s ," ",
   "sequence ",@sequence.to_s ," ",
   "title ",@title.to_s ," ",
   "refid ",@refid.to_s ," " ].join
end

#transition(x) ⇒ Object



144
145
146
# File 'lib/soby/slide.rb', line 144

def transition x 
  @transition.call x 
end