Class: NcsNavigator::Mdes::VariableType

Inherits:
Object
  • Object
show all
Defined in:
lib/ncs_navigator/warehouse/table_modeler/mdes_ext.rb

Instance Method Summary collapse

Instance Method Details

#wh_max_lengthObject



119
120
121
122
123
124
125
126
127
# File 'lib/ncs_navigator/warehouse/table_modeler/mdes_ext.rb', line 119

def wh_max_length
  @wh_max_length ||=
    case
    when max_length
      max_length
    when code_list
      code_list.collect { |c| c.value.size }.max
    end
end

#wh_min_lengthObject



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ncs_navigator/warehouse/table_modeler/mdes_ext.rb', line 129

def wh_min_length
  @wh_min_length ||=
    case
    when min_length
      min_length
    when code_list
      code_list.collect { |c| c.value.size }.min
    else
      0
    end
end

#wh_property_typeObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ncs_navigator/warehouse/table_modeler/mdes_ext.rb', line 141

def wh_property_type
  @wh_property_type ||=
    case base_type
    when :string
      if code_list || pattern || (wh_max_length && wh_max_length < 1000)
        NcsNavigator::Warehouse::DataMapper::NcsString
      else
        NcsNavigator::Warehouse::DataMapper::NcsText
      end
    when :int
      NcsNavigator::Warehouse::DataMapper::NcsInteger
    when :decimal
      NcsNavigator::Warehouse::DataMapper::NcsDecimal
    else
      fail "Unsupported base_type #{base_type.inspect}"
    end
end

#wh_type_optionsObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ncs_navigator/warehouse/table_modeler/mdes_ext.rb', line 98

def wh_type_options
  @wh_type_options ||=
    begin
      options = OrderedHash.new
      options[:length] = (wh_min_length..wh_max_length) if wh_max_length
      options[:set] = code_list.collect(&:value) if code_list
      options[:format] = pattern if pattern

      if wh_property_type == NcsNavigator::Warehouse::DataMapper::NcsDecimal
        # While PostgreSQL supports arbitrary precision DECIMALs,
        # DataMapper doesn't. However PostgreSQL uses flexible
        # storage for DECIMALs, so a larger-than-ever-needed
        # precision should be fine.
        options[:precision] = 128
        options[:scale] = 64
      end

      options
    end
end