Class: Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::FloatVal::NonEmpty
- Inherits:
-
Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::FloatVal
show all
- Extended by:
- Operators::Binary, Operators::Relational, Operators::Unary
- Includes:
- Comparable
- Defined in:
- lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb
Overview
Non-empty numeric value. Shouldn't be directly instantiated --
instead, use the value constructors.
Instance Attribute Summary (collapse)
#position, #usage
Instance Method Summary
(collapse)
unary_operators
relational_operators
binary_operators
empty, #numeric?, #too_short?, value
#allowed?, #component?, #date?, #definition, #id?, #leaf?, #numeric?, #simple?, #string?, #time?
#element?, #size
#blank?, #characters, #component?, #composite?, #definition, #element?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?
Methods included from Color
ansi, #ansi
Constructor Details
- (NonEmpty) initialize(value, usage, position)
A new instance of NonEmpty
187
188
189
190
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 187
def initialize(value, usage, position)
@value = value
super(usage, position)
end
|
Instance Attribute Details
183
184
185
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 183
def value
@value
end
|
Instance Method Details
- coerce(other)
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 200
def coerce(other)
if other.respond_to?(:to_d)
return copy(:value => other.to_d), self
else
raise TypeError,
"cannot coerce FloatVal to #{other.class}"
end
end
|
- (NonEmpty) copy(changes = {})
193
194
195
196
197
198
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 193
def copy(changes = {})
NonEmpty.new \
changes.fetch(:value, @value),
changes.fetch(:usage, usage),
changes.fetch(:position, position)
end
|
- (Boolean) empty?
216
217
218
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 216
def empty?
false
end
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 221
def inspect
id = definition.try do |d|
"[#{'% 5s' % d.id}: #{d.name}]".bind do |s|
if usage.forbidden?
ansi.forbidden(s)
elsif usage.required?
ansi.required(s)
else
ansi.optional(s)
end
end
end
ansi.element(" R.value#{id}") << "(#{to_s})"
end
|
309
310
311
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 309
def map
FloatVal.value(yield(@value), usage, position)
end
|
238
239
240
241
242
243
244
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 238
def to_s
if definition.max_precision.present?
@value.round(definition.max_precision).to_s("F")
else
@value.to_s("F")
end
end
|
- (String) to_x12(truncate = true)
While the ASC X12 standard supports the usage of exponential
notation, the HIPAA guides prohibit it. In the interest of
simplicity, this method will not output exponential notation,
as there is currently no configuration attribute to indicate
if this is allowed or not -- if this is required in the future,
the best place for it to fit would be in SimpleElementUse
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 254
def to_x12(truncate = true)
remaining =
if @value.to_i.zero?
definition.max_length
else
definition.max_length - @value.to_i.abs.to_s.length
end
if remaining <= 0
if truncate
int = @value.to_i.to_s
sign = (int < 0) ? "-" : ""
return sign << int.abs.to_s.take(definition.max_length)
else
return @value.to_i.abs
end
end
precision =
if definition.max_precision.present?
(definition.max_precision < remaining) ?
definition.max_precision : remaining
else
remaining
end
rounded = @value.round(precision)
sign = (rounded < 0) ? "-" : ""
if rounded.zero?
"0" * definition.min_length
else
sign << rounded.abs.to_s("F").
gsub(/^0+/, ""). gsub(/0+$/, ""). gsub(/\.$/, ""). rjust(definition.min_length, "0")
end
end
|
- (Boolean) too_long?
299
300
301
302
303
304
305
306
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 299
def too_long?
definition.max_length < @value.to_i.abs.to_s.length
end
|
- (Boolean) valid?
211
212
213
214
|
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/float_val.rb', line 211
def valid?
@value.finite?
end
|