Class: GreenPepper::ArrayType

Inherits:
TypeBase
  • Object
show all
Defined in:
lib/greenpepper/converter.rb

Class Method Summary collapse

Methods inherited from TypeBase

can_parse?, inherited

Class Method Details

.convertObject



310
311
312
313
314
315
316
317
318
# File 'lib/greenpepper/converter.rb', line 310

def self.convert
  Proc.new{ |s|
    data = ArrayGrammarModule.parse(s)
    
    data.collect{ |x|
      TypeConverter.instance.convert_string x
    }
  }
end

.formatObject



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/greenpepper/converter.rb', line 320

def self.format
  Proc.new{ |a,expected_format|
    if a != nil
      expected = ArrayGrammarModule.parse(expected_format)

      a.each_index{|i|
        a[i] = TypeConverter.instance.format_object expected[i], 
          a[i]
      }

      case expected_format
      when /^\[([^,]*,)*\]$/
        "[" + a.join(",") + ",]"
      when /^\[([^,]*,?)*\]$/
        "[" + a.join(",") + "]"
      when /^([^,]+,)+[^,]+,$/
        a.join(",") + ","
      else
        a.join(",")
      end
    else
      ""
    end
  }
end

.regexObject



306
307
308
# File 'lib/greenpepper/converter.rb', line 306

def self.regex
  /^\s*(\[([^,]*,?)*\])|(([^,]+,)+[^,]+,?)\s*$/
end