Sha256: 9d519a4619869509eeae34999d7b518862e88336cfbfb446244173c32ba893f1

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'pathname'

module Scissor
  class Fragment
    attr_reader :filename, :start, :duration

    def initialize(filename, start, duration, reverse = false)
      @filename = Pathname.new(filename)
      @start = start
      @duration = duration
      @reverse = reverse

      freeze
    end

    def reversed?
      @reverse
    end

    def create(remaining_start, remaining_length)
      new_fragment = nil

      if remaining_start >= duration
        remaining_start -= duration
      else
        if remaining_start + remaining_length >= duration
          new_fragment = self.class.new(
            filename,
            start + remaining_start,
            duration - remaining_start)

          remaining_length -= (duration - remaining_start)
          remaining_start = 0
        else
          new_fragment = self.class.new(
            filename,
            start + remaining_start,
            remaining_length)

          remaining_start = 0
          remaining_length = 0
        end
      end

      return new_fragment, remaining_start, remaining_length
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
youpy-scissor-0.0.16 lib/scissor/fragment.rb
youpy-scissor-0.0.17 lib/scissor/fragment.rb
youpy-scissor-0.0.18 lib/scissor/fragment.rb