Class: Ezframe::IntType
Instance Attribute Summary
Attributes inherited from TypeBase
#attribute, #error, #parent
Instance Method Summary
collapse
Methods inherited from TypeBase
#db_value, get_class, #initialize, #key, #label, #multi_inputs?, #no_edit?, #no_view?, #type, type_name, #use_view_format, #value
Instance Method Details
221
222
223
|
# File 'lib/ezframe/column_type.rb', line 221
def db_type
return "int"
end
|
204
205
206
207
208
209
210
211
|
# File 'lib/ezframe/column_type.rb', line 204
def form(opts = {})
return nil if no_edit? && !opts[:force]
key = self.key
key ="#{key}#{opts[:key_suffix]}" if opts[:key_suffix]
h = Ht.input(type: "number", name: key, label: @attribute[:label], value: @value || "")
h[:class] = @attribute[:class] if @attribute[:class]
return h
end
|
#normalize(val) ⇒ Object
174
175
176
177
178
179
|
# File 'lib/ezframe/column_type.rb', line 174
def normalize(val)
if val.is_a?(String)
val = val.tr("0-9", "0-9").strip
end
return val
end
|
#validate(val) ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/ezframe/column_type.rb', line 213
def validate(val)
return nil if !val || val.to_s.strip.empty?
unless /^\d+$/ =~ val.to_s
return :invalid_value
end
return nil
end
|
#value=(v) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/ezframe/column_type.rb', line 181
def value=(v)
if v.nil?
default = @attribute[:default]
if default
@value = default
else
@value = nil
end
return
end
if v.nil?
@value = nil
return
end
unless v.is_a?(Integer) || v.is_a?(String)
EzLog.debug("value must integer or string: key=#{self.key}, #{v}: class=#{v.class}")
return
end
v = normalize(v)
@value = v.to_i
end
|
#view(opts = {}) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/ezframe/column_type.rb', line 159
def view(opts = {})
return nil if no_view? && !opts[:force]
return nil unless @value
return nil if @attribute[:no_view_if_zero] && @value.to_i == 0
if @attribute[:view_format]
return use_view_format(@attribute[:view_format], @value)
else
if @attribute[:add_comma]
return @value.to_i.add_comma
else
return @value.to_s
end
end
end
|