Class: MultimediaParadise::StartLengthDuration

Inherits:
Object
  • Object
show all
Includes:
Colours
Defined in:
lib/multimedia_paradise/multimedia/start_length_duration.rb

Overview

MultimediaParadise::StartLengthDuration

Constant Summary collapse

DEBUG =
#

DEBUG

#
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(optional_input_duration = nil) ⇒ StartLengthDuration

#

initialize

#


44
45
46
47
48
49
50
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 44

def initialize(
    optional_input_duration = nil
  )
  set_duration(optional_input_duration) if optional_input_duration
  reset # set them to 0.
  ensure_proper_values
end

Instance Attribute Details

#durationObject (readonly)

Keeps the right values for the duration. In seconds.



32
33
34
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 32

def duration
  @duration
end

#lengthObject

The length, in seconds.



30
31
32
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 30

def length
  @length
end

#startObject

Specify where to start. In seconds.



31
32
33
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 31

def start
  @start
end

Instance Method Details

#be_verboseObject

#

be_verbose

#


108
109
110
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 108

def be_verbose
  @debug = true
end

#calculate_spanObject

#

calculate_span

#


88
89
90
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 88

def calculate_span # the @span is start to duration. Like: '30-50'
  @span = "#{@start}-"+(@start + @duration).to_s
end

#debug?Boolean

#

debug?

#

Returns:

  • (Boolean)


149
150
151
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 149

def debug?
  @debug
end

#ensure_proper_valuesObject

#

ensure_proper_values

#


139
140
141
142
143
144
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 139

def ensure_proper_values # We must keep them as integers and as positives.
  @length   = @length.to_f.abs
  @start    = @start.to_f.abs
  @duration = @duration.to_f.abs
  @span     = @span.to_s # is a string.
end

#feedbackObject Also known as: debug

#

feedback

#


95
96
97
98
99
100
101
102
103
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 95

def feedback
  cliner {
    e 'Length (Total length of this video file, in seconds): '+
       simp(@length.to_s)
    e 'Start: '+simp(@start.to_s)
    e 'Duration: '+simp(@duration.to_s)
    e 'Span: '+simp(@span)
  }
end

#resetObject Also known as: initialize_variables

#

reset (reset tag)

#


55
56
57
58
59
60
61
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 55

def reset
  @length   = 0
  @start    = 0
  @duration = 0
  @span     = 0
  @debug    = DEBUG
end

#set_duration(i) ⇒ Object Also known as: set_duration=

#

set_duration

Use this method when you want to set the @duration variable. This is the actual powerhorse of this script. Since Oct 2012 we will use the absolute value of any given input.

#


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 160

def set_duration(i)
  i = i.to_s
  e "The Input to duration was: `"+sfancy(i)+'`' if debug?
  count = i.count('%') # How many of these do we have?
  if i.include? '%' # Ok, it could include one % or two %
    if count > 1  # has at least two.
      i = i.gsub(/%/,'') # get rid of the % first.
      # Now we assume that the two numbers given work in %
      start_pos, end_pos = i.split('-') # in percent.
      one_percent_is = length / 100.0
      start_pos = one_percent_is * start_pos.to_i
      end_pos   = (one_percent_is * end_pos.to_i) - start_pos
      set_start(start_pos)
      i = end_pos
    else
      i = i.gsub(/%/,'') # get rid of the % first.
      one_percent_is = length / 100.0
      i = one_percent_is * i.to_i
    end
  end
  if i.to_s.include? '-' # Assume negative number means from right end.
    set_start(@length - i.to_i.abs) if count < 2
  end
  @duration = i # Set @duration finally.
  ensure_proper_values
  calculate_span # This is a dependent variable.
end

#set_end(i) ⇒ Object

#

set_end

#


66
67
68
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 66

def set_end(i) # a bit cheating here. Depends on @start.
  set_duration(i.to_i - @start)
end

#set_length(i) ⇒ Object

#

set_length

#


73
74
75
76
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 73

def set_length(i)
  @length = i.to_f
  ensure_proper_values
end

#set_start(i) ⇒ Object

#

set_start

#


131
132
133
134
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 131

def set_start(i) # Use only this method to modify @start.
  @start = i.to_f
  ensure_proper_values
end

#span?Boolean Also known as: span

#

span?

Give the total duration. Formula: start + duration. In String format.

#

Returns:

  • (Boolean)


117
118
119
# File 'lib/multimedia_paradise/multimedia/start_length_duration.rb', line 117

def span?
  @span
end