Method: FieldGenerator#apply_rules
- Defined in:
- lib/ez7gen/service/2.4/field_generator.rb
#apply_rules(codes, attributes) ⇒ Object
Handle range values specified by ‘…’ sequence, including empty range TODO refactor candidate
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'lib/ez7gen/service/2.4/field_generator.rb', line 1463 def apply_rules(codes, attributes) #safety check, no codes returns an empty map return {} if blank?(codes) #index of random element idx = sample_index(codes.size) code = codes[idx][:value] description = codes[idx][:description] if (code.include?(@@RANGE_INDICATOR)) code = handle_ranges(code) end if (code.size > (maxlen = (attributes[:max_length]) ? attributes[:max_length].to_i : code.size)) #remove all codes wich values violate #codes.select! {|it| it[:value].size <= maxlen } code, description = handle_length(codes, maxlen) end # got to have code, get an id, most basic - TODO: verify this. # if(Utils.blank?(code)) # code, description = ID({},true), '' # end # return code, description # puts code + ', ' + description return {:value => code, :description => description} end |