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

Inherits:
Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::IdentifierVal show all
Extended by:
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

#initialize(value, usage, position) ⇒ NonEmpty

Returns a new instance of NonEmpty



257
258
259
260
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 257

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

Instance Attribute Details

#valueString (readonly)

Returns:

  • (String)


231
232
233
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 231

def value
  @value
end

Instance Method Details

#coerce(other)



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

def coerce(other)
  # me, he = other.coerce(self)
  # me <OP> he
  return copy(:value => other.to_str), self
end

#copy(changes = {}) ⇒ IdentifierVal

Returns:



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

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

#inspectString

Returns:

  • (String)


295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 295

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

#to_x12(truncate = true) ⇒ String

Returns:

  • (String)


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

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

#too_long?Boolean

Returns:

  • (Boolean)


280
281
282
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 280

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

#too_short?Boolean

Returns:

  • (Boolean)


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

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

#valid?Boolean

Returns:

  • (Boolean)


276
277
278
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/identifier_val.rb', line 276

def valid?
  true
end