Class: Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::IdentifierVal::NonEmpty

Inherits:
Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::IdentifierVal show all
Extended by:
Forwardable, Operators::Relational, Operators::Unary, Operators::Wrappers
Includes:
Comparable
Defined in:
lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb

Overview

Non-empty identifier value. Shouldn't be directly instantiated -- instead, use the value constructor

Instance Attribute Summary (collapse)

Attributes inherited from Stupidedi::Values::SimpleElementVal

#position, #usage

Instance Method Summary (collapse)

Methods included from Operators::Relational

relational_operators

Methods included from Operators::Unary

unary_operators

Methods included from Operators::Wrappers

wrappers

Methods inherited from Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::IdentifierVal

empty, #id?, #map, value

Methods inherited from Stupidedi::Values::SimpleElementVal

#allowed?, #component?, #date?, #id?, #leaf?, #numeric?, #simple?, #string?, #time?

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #element?, #empty?, #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)

Returns a new instance of NonEmpty



262
263
264
265
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 262

def initialize(value, usage, position)
  @value = value
  super(usage, position)
end

Instance Attribute Details

- (String) value (readonly)

Returns:



235
236
237
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 235

def value
  @value
end

Instance Method Details

- coerce(other)



275
276
277
278
279
280
281
282
283
284
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 275

def coerce(other)
  # me, he = other.coerce(self)
  # me <OP> he
  if other.respond_to?(:to_str)
    return copy(:value => other.to_str), self
  else
    raise TypeError,
      "cannot coerce IdentifierVal to #{other.class}"
  end
end

- (IdentifierVal) copy(changes = {})

Returns:



268
269
270
271
272
273
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 268

def copy(changes = {})
  IdentifierVal.value \
    changes.fetch(:value, @value),
    changes.fetch(:usage, usage),
    changes.fetch(:position, position)
end

- (String) inspect

Returns:



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 305

def inspect
  id = definition.bind 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

  codes = definition.code_list

  if codes.try(&:internal?)
    if codes.defined_at?(@value)
      value = "#{@value}: " << ansi.dark(codes.at(@value))
    else
      value = ansi.red(@value)
    end
  else
    value = @value
  end

  ansi.element("ID.value#{id}") << "(#{value})"
end

- (String) to_x12(truncate = true)

Returns:



299
300
301
302
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 299

def to_x12(truncate = true)
  x12 = @value.ljust(definition.min_length, " ")
  truncate ? x12.take(definition.max_length) : x12
end

- (Boolean) too_long?

Returns:

  • (Boolean)


290
291
292
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 290

def too_long?
  @value.length > definition.max_length
end

- (Boolean) too_short?

Returns:

  • (Boolean)


294
295
296
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 294

def too_short?
  @value.length < definition.min_length
end

- (Boolean) valid?

Returns:

  • (Boolean)


286
287
288
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 286

def valid?
  true
end