Class: Rubyang::Database::SchemaTree::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyang/database/schema_tree.rb

Instance Method Summary collapse

Constructor Details

#initializeLength

Returns a new instance of Length.



294
295
296
# File 'lib/rubyang/database/schema_tree.rb', line 294

def initialize
  @length = [[0, 18446744073709551615]]
end

Instance Method Details

#to_sObject



332
333
334
# File 'lib/rubyang/database/schema_tree.rb', line 332

def to_s
  @length.map{ |l| "#{l[0]}..#{l[1]}" }.join( "|" )
end

#update(arg) ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/rubyang/database/schema_tree.rb', line 304

def update arg
  new_length = Array.new
  arg.delete( ' ' ).split( '|' ).each{ |length_part|
    case length_part
    when /[^\.]+\.\.[^\.]+/
      min, max = length_part.split('..')
    else
      min = max = length_part
    end
    case min
    when /^min$/
      min = @length.map{ |r| r[0] }.min
    else
      min = min.to_i
    end
    case max
    when /^max$/
      max = @length.map{ |r| r[1] }.max
    else
      max = max.to_i
    end
    unless @length.find{ |min2, max2| (min2..max2).include?( min ) && (min2..max2).include?( max ) }
      raise ArgumentError, "#{length_part} is not valid"
    end
    new_length.push [min, max]
  }
  @length = new_length
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


297
298
299
300
301
302
303
# File 'lib/rubyang/database/schema_tree.rb', line 297

def valid? value
  if @length.find{ |min2, max2| (min2..max2).include?( value.size ) }
    true
  else
    false
  end
end