Sha256: 49067fee1e2ba97d859c6b8781109a295c21fc6b5f9ecb900d159c8efaaca050

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module FHIR
  class Field

    attr_accessor :name
    attr_accessor :local_name
    attr_accessor :path
    attr_accessor :type
    attr_accessor :type_profiles
    attr_accessor :min
    attr_accessor :max
    attr_accessor :valid_codes
    attr_accessor :binding
    attr_accessor :regex
    attr_accessor :constraint

    def initialize(name='')
      @name = name
      @local_name = fix_name(@name)
      @type_profiles = []
      @valid_codes = []
    end

    def serialize
      hash = Hash.new
      self.instance_variables.each do |v|
        hash[v.to_s[1..-1]] = self.instance_variable_get(v)
      end
      hash.delete('name')
      hash.keep_if do |key,value|
        !value.nil? && (  (value.is_a?(Hash) && !value.empty?) || 
                          (value.is_a?(Array) && !value.empty?) || 
                          (!value.is_a?(Hash) && !value.is_a?(Array))
                       )
      end
      hash
    end

    def fix_name(name)
      fix = nil
      fix = "local_#{name}" if ['class','method','resourceType'].include?(name)
      fix
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fhir_models-1.6.3 lib/bootstrap/field.rb
fhir_models-1.6.2 lib/bootstrap/field.rb
fhir_models-1.6.1 lib/bootstrap/field.rb