Class: GreenPepper::ArrayType
- Defined in:
- lib/greenpepper/converter.rb
Class Method Summary collapse
Methods inherited from TypeBase
Class Method Details
.convert ⇒ Object
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 |
.format ⇒ Object
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 |
.regex ⇒ Object
306 307 308 |
# File 'lib/greenpepper/converter.rb', line 306 def self.regex /^\s*(\[([^,]*,?)*\])|(([^,]+,)+[^,]+,?)\s*$/ end |