Class: Bddgenx::TipoParam

Inherits:
Object
  • Object
show all
Defined in:
lib/bddgenx/utils/tipo_param.rb

Overview

Módulo para inferir o tipo de parâmetro a partir de exemplos

Class Method Summary collapse

Class Method Details

.determine_type(nome, estrutura) ⇒ Object

Retorna ‘string’, ‘int’, ‘float’ ou ‘boolean’



6
7
8
9
10
11
12
13
14
# File 'lib/bddgenx/utils/tipo_param.rb', line 6

def self.determine_type(nome, estrutura)
  return 'string' unless estrutura[:cabecalho].include?(nome)
  idx = estrutura[:cabecalho].index(nome)
  vals = estrutura[:linhas].map { |l| l[idx] }
  return 'boolean' if vals.all? { |v| %w[true false].include?(v.downcase) }
  return 'int'     if vals.all? { |v| v.match?(/^\d+$/) }
  return 'float'   if vals.all? { |v| v.match?(/^\d+\.\d+$/) }
  'string'
end