Class: Stupidedi::Versions::Common::ElementTypes::IdentifierVal::NonEmpty
- Inherits:
-
Valid
- Object
- Stupidedi::Values::AbstractVal
- Stupidedi::Values::AbstractElementVal
- Stupidedi::Values::SimpleElementVal
- Stupidedi::Versions::Common::ElementTypes::IdentifierVal
- Valid
- Stupidedi::Versions::Common::ElementTypes::IdentifierVal::NonEmpty
- Defined in:
- lib/stupidedi/versions/common/element_types/id.rb
Instance Attribute Summary collapse
- #value ⇒ String readonly
Attributes inherited from Stupidedi::Values::SimpleElementVal
Instance Method Summary collapse
-
#initialize(value, usage, position) ⇒ NonEmpty
constructor
A new instance of NonEmpty.
-
#inspect ⇒ String
:nocov:.
- #to_x12(truncate = true) ⇒ String
- #too_long? ⇒ Boolean
- #too_short? ⇒ Boolean
Methods inherited from Valid
#==, #coerce, #copy, #map, #valid?
Methods included from Operators::Wrappers
Methods included from Operators::Unary
Methods included from Operators::Relational
Methods inherited from Stupidedi::Versions::Common::ElementTypes::IdentifierVal
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
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
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
#value ⇒ String (readonly)
216 217 218 |
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 216 def value @value end |
Instance Method Details
#inspect ⇒ String
:nocov:
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
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
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
227 228 229 |
# File 'lib/stupidedi/versions/common/element_types/id.rb', line 227 def too_short? @value.length < definition.min_length end |