Class: Substitute::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/substitute/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Line

Returns a new instance of Line.



3
4
5
6
# File 'lib/substitute/line.rb', line 3

def initialize(text, options = {})
  self.text = text
  @srt = options[:srt]
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/substitute/line.rb', line 8

def text
  @text
end

Instance Method Details

#convert_timestamp(timestamp) ⇒ Object



34
35
36
37
38
39
# File 'lib/substitute/line.rb', line 34

def convert_timestamp(timestamp)
  times = timestamp.split(":")
  frames = times[3].to_i
  thous = (frames * 40).to_s.rjust(3, "0")
  "#{times[0..2].join(":")}#{sep}#{thous}"
end

#finishObject



30
31
32
# File 'lib/substitute/line.rb', line 30

def finish
  convert_timestamp(parts[2])
end

#identifierObject



22
23
24
# File 'lib/substitute/line.rb', line 22

def identifier
  parts[0]
end

#line_with_identifier?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/substitute/line.rb', line 50

def line_with_identifier?
  return unless parts[0]
  parts[0].to_i.to_s == parts[0]
end

#partsObject



18
19
20
# File 'lib/substitute/line.rb', line 18

def parts
  @_parts ||= text.split(" ")
end

#remaining_textObject



46
47
48
# File 'lib/substitute/line.rb', line 46

def remaining_text
  parts[3..-1].join(" ")
end

#sepObject



41
42
43
44
# File 'lib/substitute/line.rb', line 41

def sep
  return "," if srt?
  "."
end

#startObject



26
27
28
# File 'lib/substitute/line.rb', line 26

def start
  convert_timestamp(parts[1])
end

#to_sObject



10
11
12
13
14
15
16
# File 'lib/substitute/line.rb', line 10

def to_s
  if line_with_identifier?
    "\n#{identifier}\n#{start} --> #{finish}\n#{remaining_text}"
  else
    text
  end
end