class EncoderTools::CLI::Subtitles::Offset

Constants

ABSOLUTE_OFFSET
HH_MM_SS_OFFSET
MIN_PER_HOUR
NEGATIVE_OFFSET
NUMBER
POSITIVE_OFFSET
SEC_PER_MIN

Public Instance Methods

run() click to toggle source
# File lib/encoder-tools/cli/subtitles/offset.rb, line 14
def run
  value = if options[:set]
            options[:set]
          elsif options[:add]
            "+#{options[:add]}"
          elsif options[:subtract]
            "-#{options[:subtract]}"
          else
            raise ArgumentError, "Must provide a set, add, or subtract option to determine the offset"
          end

  write offset(read, value)
end

Protected Instance Methods

offset(list, value) click to toggle source
# File lib/encoder-tools/cli/subtitles/offset.rb, line 29
def offset(list, value)
  list.offset = parse_offset(list, value)
  return list
end
parse_offset(list, value) click to toggle source
# File lib/encoder-tools/cli/subtitles/offset.rb, line 34
def parse_offset(list, value)
  case value
  when Fixnum
    value
  when HH_MM_SS_OFFSET
    ((BigDecimal($1 || '0') * MIN_PER_HOUR) + BigDecimal($2)) * SEC_PER_MIN + BigDecimal($3)
  when POSITIVE_OFFSET
    list.offset + BigDecimal($1)
  when NEGATIVE_OFFSET
    list.offset - BigDecimal($1)
  when ABSOLUTE_OFFSET
    BigDecimal(value)
  end
end