Class: Stupidedi::Versions::Common::ElementTypes::IdentifierVal::NonEmpty

Inherits:
Valid show all
Defined in:
lib/stupidedi/versions/common/element_types/id.rb

Instance Attribute Summary collapse

Attributes inherited from Stupidedi::Values::SimpleElementVal

#position, #usage

Instance Method Summary collapse

Methods inherited from Valid

#==, #coerce, #copy, #map, #valid?

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::Common::ElementTypes::IdentifierVal

empty, #id?, value

Methods inherited from Stupidedi::Values::SimpleElementVal

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

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #descriptor, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #leaf?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?

Methods included from Color

ansi, #ansi

Constructor Details

#initialize(value, usage, position) ⇒ NonEmpty

Returns a new instance of NonEmpty.


218
219
220
221
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 218

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

Instance Attribute Details

#valueString (readonly)

Returns:

  • (String)

216
217
218
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 216

def value
  @value
end

Instance Method Details

#inspectString

:nocov:

Returns:

  • (String)

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 239

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

  if definition.code_list.try(&:internal?)
    if usage.allowed_values.include?(@value)
      value = "#{@value}: " + ansi.dark(definition.code_list.at(@value))
    elsif definition.code_list.defined_at?(@value)
      value = ansi.red("#{@value}: " + definition.code_list.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)

232
233
234
235
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 232

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

#too_long?Boolean

Returns:

  • (Boolean)

223
224
225
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 223

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

#too_short?Boolean

Returns:

  • (Boolean)

227
228
229
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 227

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