Sha256: e37ad601794758fb3994a4e4981d19400f56d44c367254932aef1cd05abb7458

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'pathname'

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

    def initialize(filename, start, duration, reverse = false)
      @filename = Pathname.new(filename).realpath
      @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

2 entries across 2 versions & 1 rubygems

Version Path
youpy-scissor-0.0.19 lib/scissor/fragment.rb
youpy-scissor-0.0.20 lib/scissor/fragment.rb