class MultimediaParadise::StartLengthDuration

Constants

DEBUG
#

DEBUG

#

Attributes

duration[R]
length[R]
start[R]

Public Class Methods

new( optional_input_duration = nil ) click to toggle source
#

initialize

#
# 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

Public Instance Methods

be_verbose() click to toggle source
#

be_verbose

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 108
def be_verbose
  @debug = true
end
calculate_span() click to toggle source
#

calculate_span

#
# 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.to_s+'-'+(@start + @duration).to_s
end
debug()
Alias for: feedback
debug?() click to toggle source
#

debug?

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 149
def debug?
  @debug
end
ensure_proper_values() click to toggle source
#

ensure_proper_values

#
# 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
feedback() click to toggle source
#

feedback

#
# 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
Also aliased as: debug
initialize_variables()
Alias for: reset
length=(i) click to toggle source
#

length=

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 81
def length=(i) # an alias to set_length
  set_length(i)
end
reset() click to toggle source
#

reset

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 55
def reset
  @length   = 0
  @start    = 0
  @duration = 0
  @span     = 0
  @debug    = DEBUG
end
Also aliased as: initialize_variables
set_duration(i) click to toggle source
#

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.

#
# 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
Also aliased as: set_duration=
set_duration=(i)
Alias for: set_duration
set_end(i) click to toggle source
#

set_end

#
# 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) click to toggle source
#

set_length

#
# 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) click to toggle source
#

set_start

#
# 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()
Alias for: span?
span?() click to toggle source
#

span?

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

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 117
def span?
  @span
end
Also aliased as: span
start=(i) click to toggle source
#

start=

#
# File lib/multimedia_paradise/multimedia/start_length_duration.rb, line 124
def start=(i) # wrapper to the above.
  set_start(i)
end