Class: Scissor::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/scissor/fragment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, start, duration, reverse = false) ⇒ Fragment

Returns a new instance of Fragment.



7
8
9
10
11
12
13
14
# File 'lib/scissor/fragment.rb', line 7

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

  freeze
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def duration
  @duration
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def filename
  @filename
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def start
  @start
end

Instance Method Details

#create(remaining_start, remaining_length) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scissor/fragment.rb', line 20

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

#reversed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/scissor/fragment.rb', line 16

def reversed?
  @reverse
end