lib/rio/matchrecord.rb in rio-0.3.1 vs lib/rio/matchrecord.rb in rio-0.3.2

- old
+ new

@@ -78,10 +78,20 @@ def =~(record) #p "=~(#{record},#{record.recno}) select_arg=#{@select_arg}" @select_arg === record.recno end end + class Fixnum < Base + def match?(val,recno) + #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" + @select_arg === recno + end + def =~(record) + #p "=~(#{record},#{record.recno}) select_arg=#{@select_arg}" + @select_arg === record.recno + end + end class Proc < Base def initialize(arg,therio) super(arg) @therio = therio end @@ -125,10 +135,14 @@ #p "SelList(#{args.inspect},#{@list.inspect})" end def inspect @list.inspect end + def size() @list.size unless @list.nil? end + def only_one_fixnum?() + @list && @list.size == 1 && @list[0].kind_of?(Match::Record::Fixnum) + end def delete_at(index) @list.delete_at(index) @list = nil if @list.empty? end def self.create(therio,args) @@ -155,12 +169,14 @@ Match::Record::Range.new(arg) when ::Proc Match::Record::Proc.new(arg,therio) when ::Symbol Match::Record::Symbol.new(arg) + when ::Fixnum + Match::Record::Fixnum.new(arg) else - Match::Record::Range.new(::Range.new(arg,arg)) + raise ArgumentError,"Argument must be a Regexp,Range,Fixnum,Proc, or Symbol" end end def match?(val,recno) # !@list.nil? && (@list.empty? || @list.detect { |sel| sel.match?(val,recno) } || false) && true return false if @list.nil? @@ -185,9 +201,12 @@ class SelRej def initialize(therio,sel_args,rej_args) @sel = SelList.create(therio,sel_args) @rej = SelList.create(therio,rej_args) @always = init_always() + end + def only_one_fixnum?() + @rej.nil? && @sel && @sel.only_one_fixnum? end def init_always(reset=false) if @sel.nil? and @rej.nil? !reset elsif @rej.nil? and @sel.always?