lib/rio/entrysel.rb in rio-0.3.7 vs lib/rio/entrysel.rb in rio-0.3.8
- old
+ new
@@ -1,8 +1,8 @@
#--
# ===============================================================================
-# Copyright (c) 2005, Christopher Kleckner
+# Copyright (c) 2005, 2006 Christopher Kleckner
# All rights reserved
#
# This file is part of the Rio library for ruby.
#
# Rio is free software; you can redistribute it and/or modify
@@ -20,11 +20,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ===============================================================================
#++
#
# To create the documentation for Rio run the command
-# rake rdoc
+# ruby build_doc.rb
# from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
#
# Suggested Reading
# * RIO::Doc::SYNOPSIS
# * RIO::Doc::INTRO
@@ -54,22 +54,41 @@
end
def ===(el) self =~ el end
abstract_method :=~
end
+ class Depth < Base
+ def =~(entry)
+ @match_to === entry.rl.pathdepth
+ end
+ end
class Any < Base
def =~(entry) true end
end
class None < Base
def =~(entry) false end
end
class Glob < Base
- def =~(entry) Impl::U.fnmatch?(entry.filename.to_s,@match_to) end
+ def =~(entry)
+ ::File.fnmatch?(@match_to,entry.filename.to_s)
+ end
end
class Regexp < Base
- def =~(entry) @match_to =~ entry.filename.to_s end
+ def =~(entry)
+ @match_to =~ entry.filename.to_s
+ end
end
+ class PathGlob < Base
+ def =~(entry)
+ ::File.fnmatch?(@match_to,entry.to_s)
+ end
+ end
+ class PathRegexp < Base
+ def =~(entry)
+ @match_to =~ entry.to_s
+ end
+ end
class Proc < Base
def =~(entry) @match_to[entry] end
end
class Symbol < Base
def =~(entry) entry.__send__(@match_to) end
@@ -82,10 +101,12 @@
(@match_to.empty? or @match_to.all? { |sel| sel =~ el })
end
end
def create(arg)
case arg
+ when ::Fixnum then Depth.new(arg)
+ when ::Range then Depth.new(arg)
when ::String then Glob.new(arg)
when ::Regexp then Regexp.new(arg)
when ::Proc then Proc.new(arg)
when ::Symbol then Symbol.new(arg)
when ::TrueClass then Any.new(arg)
@@ -126,11 +147,9 @@
self.class.to_s+'['+self.to_s+']'+'.'+func.to_s+'('+args.join(',')+')'
end
end
class Sels < Array
def <<(entry_list)
- #p callstr('<<',entry_list)
-
same_sym = self.grep(entry_list)
if same_sym.empty?
super
else
same_sym[0].list = entry_list.list