Sha256: 9ff9e7cfbdf9881beb9f798d499471ee397eb0ead2111d74e45f281e46922588

Contents?: true

Size: 1.33 KB

Versions: 33

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'ehbrs/videos/series/rename/line_result'

module Ehbrs
  module Videos
    module Series
      module Rename
        class File < ::Ehbrs::Videos::Series::Rename::LineResult
          module BasenameParser
            FORMATS = [{
              format: /(\d+)(\d{2})(\d{2})/i,
              build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
            }, {
              format: /s(\d+)e(\d+)-(\d+)/i,
              build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
            }, {
              format: /(\d{1,2})\s*[^\d]\s*(\d{2})/i,
              build: ->(m) { { s: padding(m[1]), e: padding(m[2]) } }
            }, {
              format: /(\d+)(\d{2})/i,
              build: ->(m) { { s: padding(m[1]), e: padding(m[2]) } }
            }, {
              format: /(\d{2})/i,
              build: ->(m) { { s: padding(1), e: padding(m[1]) } }
            }].freeze

            def self.padding(string)
              string.to_s.rjust(2, '0')
            end

            def parse_uncached
              FORMATS.each do |format|
                m = format.fetch(:format).match(current_name)
                return format.fetch(:build).call(m) if m
              end
              nil
            end
          end
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ehbrs-tools-0.30.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.29.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.28.3 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.28.2 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.28.1 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.28.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.27.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.26.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.25.1 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.25.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.24.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.23.1 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.23.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.22.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.21.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.20.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.19.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.18.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.17.0 lib/ehbrs/videos/series/rename/file/basename_parser.rb
ehbrs-tools-0.16.5 lib/ehbrs/videos/series/rename/file/basename_parser.rb