Sha256: 155468e319ec21ede3844b904f239376b11e0c806808c4fc304209ed3e21fc9f

Contents?: true

Size: 673 Bytes

Versions: 2

Compression:

Stored size: 673 Bytes

Contents

#
# File::      FileComparison.rb
# Author::    wkm
# Copyright:: 2009
# License::   GPL
#
# Adds File.equivalent? that tries to guess whether two files are equivalent
#

require 'sitefuel/extensions/ArrayComparisons'

class File
  # gives true if one of the paths is the ending of another path
  #
  #  File.equivalent?('b/a.rb', 'a.rb')  # ==> true
  #  File.equivalent?('c/b/a.rb', 'c/a.rb')  # ==> false
  def self.equivalent?(a, b)
    list = [
      File.expand_path(a, '/').split(File::SEPARATOR)[1 .. -1],
      File.expand_path(b, '/').split(File::SEPARATOR)[1 .. -1]
    ].sort {|l,r| l.length <=> r.length }.reverse
    list.first.ends_with? list.last
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sitefuel-0.0.0b lib/sitefuel/extensions/FileComparison.rb
sitefuel-0.0.0a lib/sitefuel/extensions/FileComparison.rb