Sha256: d9edac61c0fdb2aba9b1f8aa99b2bd0c0fe7c8c368cbe58fbd71073790e3f62b

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'ostruct'

module Trizetto
  module Api
    module Eligibility
      module WebService

        # Base class for parsed reponses in the eligibility response.
        class Node < OpenStruct
          def initialize(raw_hash = {})
            required_keys = self.class.constants.include?(:REQUIRED_KEYS) ? self.class::REQUIRED_KEYS : {}
            clean_hash = required_keys.merge(raw_hash)

            cleanup_keys = self.class.constants.include?(:KEY_CLEANUP) ? self.class::KEY_CLEANUP : {}
            cleanup_keys.each do |uglykey, friendly_key|
              clean_hash[friendly_key] = clean_hash.delete(uglykey) if clean_hash.has_key?(uglykey)
            end

            # Convert prefixed keys "benefit_related_entity_id" to simple keys "id"
            prefix_translations = self.class.constants.include?(:PREFIX_TRANSLATIONS) ? self.class::PREFIX_TRANSLATIONS : {}
            prefix_translations.each do |key_prefix|
              clean_hash.keys.each do |key|
                if key.to_s =~ /^#{key_prefix}_(.*)$/
                  clean_hash["#{$1}".to_sym] = clean_hash.delete(key)
                end
              end
            end

            super(clean_hash)

            after_inititlize(clean_hash)
          end

          # Callback after the prased eligibility response has been cleaned up
          def after_inititlize(hash)
          end
          protected :after_inititlize
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trizetto-api-0.2.1 lib/trizetto/api/eligibility/web_service/node.rb