Sha256: 4132042f2b1838e5f7027ef36eb81c0fa39748a1a2993b3e6f5780309166c2a9

Contents?: true

Size: 1.14 KB

Versions: 142

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Renalware
  class Gender
    include ActiveModel::Model
    attr_reader :code

    DATA = {
      "NK" => "Not Known",
      "M" => "Male",
      "F" => "Female",
      "NS" => "Not Specified"
    }.freeze

    SALUTATIONS = {
      "NK" => "",
      "M" => "Mr",
      "F" => "Ms",
      "NS" => ""
    }.freeze

    NHS_DICTIONARY_NUMBERS = {
      "NK" => 0,
      "M" => 1,
      "F" => 2,
      "NS" => 9
    }.freeze

    def self.all
      DATA.map { |code, _| new(code) }
    end

    # @section serialization
    #
    def self.load(raw_string)
      new(raw_string)
    end

    def self.dump(gender)
      gender.to_str
    end

    def initialize(code)
      @code = code && ActiveSupport::StringInquirer.new(code)
    end

    # @section validations
    #
    validates :code, inclusion: { in: DATA.keys }

    # @section attributes
    #

    def name
      DATA[code]
    end

    def salutation
      SALUTATIONS[code]
    end

    def nhs_dictionary_number
      NHS_DICTIONARY_NUMBERS[code]
    end

    # @section coercions
    #
    def to_s
      code
    end

    def to_str
      code
    end
  end
end

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/values/renalware/gender.rb
renalware-core-2.1.0 app/values/renalware/gender.rb
renalware-core-2.0.167 app/values/renalware/gender.rb
renalware-core-2.0.166 app/values/renalware/gender.rb
renalware-core-2.0.165 app/values/renalware/gender.rb
renalware-core-2.0.164 app/values/renalware/gender.rb
renalware-core-2.0.163 app/values/renalware/gender.rb
renalware-core-2.0.162 app/values/renalware/gender.rb
renalware-core-2.0.161 app/values/renalware/gender.rb
renalware-core-2.0.160 app/values/renalware/gender.rb
renalware-core-2.0.159 app/values/renalware/gender.rb
renalware-core-2.0.158 app/values/renalware/gender.rb
renalware-core-2.0.157 app/values/renalware/gender.rb
renalware-core-2.0.156 app/values/renalware/gender.rb
renalware-core-2.0.155 app/values/renalware/gender.rb
renalware-core-2.0.153 app/values/renalware/gender.rb
renalware-core-2.0.152 app/values/renalware/gender.rb
renalware-core-2.0.151 app/values/renalware/gender.rb
renalware-core-2.0.149 app/values/renalware/gender.rb
renalware-core-2.0.148 app/values/renalware/gender.rb