module YAHL7::V2::AliasFieldNames::ClassMethods

This is the module that actually extends the segment.

Public Instance Methods

define_field_names(mappings) click to toggle source

This method is used to define the field name mappings for the data type / segment.

It is possible to return a string, in which case you can use an integer value. If you want to return a specific data type, you must use a hash instead, in the form of (for example):

define_field_names({
  some_field: 0,
  some_other_field: { index: 1, class: YAHL7::V2::DataType::TS }
})

This defines the method `some_field` which returns a string, while the other method `some_other_field` returns either a `nil` value or a `YAHL7::V2::DataType::TS` value.

It is possible that the field is repeatable. If so, it is up to the data type to define a `::repeated?` method that receives the raw value and then it determines if the field was repeated or not. If it is repeatable and it is determined to be repeated, an array of that type is returned.

# File lib/yahl7/v2/alias_field_names.rb, line 70
def define_field_names(mappings)
  mappings.each do |name, mapping|
    case mapping
    when Integer then define_method(name) { normalize_value(self[mapping]) }
    when Hash then define_method(name) { make_field(mapping[:class], self[mapping[:index]]) }
    end
  end
end