Class: RIO::Match::Record::SelList

Inherits:
Object
  • Object
show all
Defined in:
lib/rio/matchrecord.rb

Overview

for a sellist nil indicates no call was made, so nothing selected empty indicates a call was made, so all selected contents should be checked for matches if contents are removed the list should become nil, not empty

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(therio, args) ⇒ SelList

Returns a new instance of SelList.



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rio/matchrecord.rb', line 146

def initialize(therio,args)
  if args.nil?
    @list = nil
  else
    @list = []
    args.each do |arg|
      @list << create_sel(therio,arg)
    end
  end
  #p "SelList(#{args.inspect},#{@list.inspect})"
end

Class Method Details

.create(therio, args) ⇒ Object



168
169
170
# File 'lib/rio/matchrecord.rb', line 168

def self.create(therio,args)
  new(therio,args) unless args.nil?
end

Instance Method Details

#always?Boolean

Returns:

  • (Boolean)


216
# File 'lib/rio/matchrecord.rb', line 216

def always?() !@list.nil? && @list.empty? end

#create_sel(therio, arg) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/rio/matchrecord.rb', line 184

def create_sel(therio,arg)
  Match::Record.create(therio,arg)
#           case arg
#           when ::Regexp
#             Match::Record::RegExp.new(arg)
#           when ::Range
#             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)
#           when ::Array
#             Match::Record::And.new(arg)
#           else
#             raise ArgumentError,"Argument must be a Regexp,Range,Fixnum,Proc, or Symbol"
#           end
end

#delete_at(index) ⇒ Object



164
165
166
167
# File 'lib/rio/matchrecord.rb', line 164

def delete_at(index)
  @list.delete_at(index)
  @list = nil if @list.empty?
end

#inspectObject

p “SelList(#RIO::Match::Record::SelList.argsargs.inspect,#RIO::Match::Record::SelList.@[email protected])”



157
158
159
# File 'lib/rio/matchrecord.rb', line 157

def inspect
  @list.inspect
end

#match?(val, recno) ⇒ Boolean

end

Returns:

  • (Boolean)


203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/rio/matchrecord.rb', line 203

def match?(val,recno)
  # [email protected]? && (@list.empty? || @list.detect { |sel| sel.match?(val,recno) } || false) && true
  return false if @list.nil?
  return true if @list.empty?
  as = nil
  al = @list.detect { |sel| as = sel.match?(val,recno)
    #p "1: #{$1} as[match?]: #{as.inspect}"
    as
  }
  #p "[SelList.match?] as:#{as.inspect} al:#{al.inspect}"
  return as if al
  return false
end

#never?Boolean

Returns:

  • (Boolean)


217
# File 'lib/rio/matchrecord.rb', line 217

def never?() @list.nil? end

#only_one_fixnum?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/rio/matchrecord.rb', line 161

def only_one_fixnum?()
  @list && @list.size == 1 && @list[0].kind_of?(Match::Record::Fixnum)
end

#rangesObject



171
172
173
# File 'lib/rio/matchrecord.rb', line 171

def ranges()
  @list.nil? ? [] : @list.select { |sel| sel.kind_of?(Record::Range) }
end

#remove_passed_ranges(n) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'lib/rio/matchrecord.rb', line 174

def remove_passed_ranges(n)
  return nil if @list.nil?
  return self if @list.empty?
  newlist = []
  @list.each do |sel| 
    newlist << sel unless sel.kind_of?(Match::Record::Range) and sel.val.max < n 
  end
  @list = (newlist.empty? ? nil : newlist) if newlist.length != @list.length
  @list.nil? ? nil : self
end

#sizeObject



160
# File 'lib/rio/matchrecord.rb', line 160

def size() @list.size unless @list.nil? end