Class: Stupidedi::Versions::Common::ElementTypes::StringVal::NonEmpty

Inherits:
Valid show all
Defined in:
lib/stupidedi/versions/common/element_types/an.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::StringVal

empty, #string?, 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(string, usage, position) ⇒ NonEmpty

Returns a new instance of NonEmpty.


296
297
298
299
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 296

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

Instance Attribute Details

#valueString (readonly)

Returns:

  • (String)

294
295
296
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 294

def value
  @value
end

Instance Method Details

#inspectString

:nocov:

Returns:

  • (String)

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 317

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

  ansi.element("AN.value#{id}") + "(#{@value})"
end

#to_date(format)


335
336
337
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 335

def to_date(format)
  AN.strptime(format, @value)
end

#to_x12(truncate = true) ⇒ String

Returns:

  • (String)

310
311
312
313
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 310

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

#too_long?Boolean

Returns:

  • (Boolean)

301
302
303
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 301

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

#too_short?Boolean

Returns:

  • (Boolean)

305
306
307
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 305

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