Sha256: 054b6dc20d45d1960bf79b1aef025fc062bb02e3c93f260244ba3da16ff4cdcd

Contents?: true

Size: 1.3 KB

Versions: 44

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Ehbrs
  module Vg
    module Wii
      module Wit
        class Path
          WIT_PATH_PATTERN = /\A(?:([a-z0-9]+):)?(.+)\z/i.freeze

          class << self
            def assert(source)
              source = parse(source) unless source.is_a?(self)
              source
            end

            def parse(path)
              WIT_PATH_PATTERN
                .match(path)
                .if_present { |m| new(m[1], m[2]) }
                .if_blank { raise "\"#{WIT_PATH_PATTERN}\" does not match \"#{path}\"" }
            end
          end

          common_constructor :type, :path do
            self.type = type.to_s.upcase
            self.path = ::Pathname.new(path.to_s)
          end

          def change?(other)
            type_change?(other) || path_change?(other)
          end

          def path_change?(other)
            path.expand_path.to_s != other.path.expand_path.to_s
          end

          def to_s
            r = path.to_s
            r = "#{type.to_s.upcase}:#{r}" if type.present?
            r
          end

          def type_change?(other)
            return false if other.type.blank?
            return true if type.blank?

            type != other.type
          end
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
ehbrs-tools-0.35.1 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.35.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.34.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.33.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.32.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.31.1 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.31.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.30.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.29.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.28.3 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.28.2 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.28.1 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.28.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.27.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.26.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.25.1 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.25.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.24.0 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.23.1 lib/ehbrs/vg/wii/wit/path.rb
ehbrs-tools-0.23.0 lib/ehbrs/vg/wii/wit/path.rb