Sha256: 7fbb582d5ca426d79e7ec85f6e9a10625f0430c80ca1fa00a4eb21512224d329

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'ehbrs_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Music
    module Sort
      module Files
        class Base
          common_constructor :section, :order, :name, :original_path, :padding, default: [nil, 0] do
            self.original_path = original_path.if_present { |v| v.to_pathname.expand_path }
          end

          def reorder(new_section, new_order, padding)
            self.class.new(new_section, new_order, name, original_path, padding)
          end

          def target_basename
            "#{section}#{order.to_s.rjust(padding, '0')} #{name}"
          end

          def source_basename
            original_path.if_present(&:basename) || raise('Original path is blank')
          end

          def to_s
            target_basename
          end

          private

          def <=>(other)
            %i[section order name].each do |a|
              r = send(a) <=> other.send(a)
              return r unless r.zero?
            end
            0
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.3 lib/ehbrs_ruby_utils/music/sort/files/base.rb
ehbrs_ruby_utils-0.44.2 lib/ehbrs_ruby_utils/music/sort/files/base.rb
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/music/sort/files/base.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/music/sort/files/base.rb