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.0.62 app/values/renalware/gender.rb
renalware-core-2.0.61 app/values/renalware/gender.rb
renalware-core-2.0.60 app/values/renalware/gender.rb
renalware-core-2.0.58 app/values/renalware/gender.rb
renalware-core-2.0.57 app/values/renalware/gender.rb
renalware-core-2.0.56 app/values/renalware/gender.rb
renalware-core-2.0.55 app/values/renalware/gender.rb
renalware-core-2.0.54 app/values/renalware/gender.rb
renalware-core-2.0.53 app/values/renalware/gender.rb
renalware-core-2.0.52 app/values/renalware/gender.rb
renalware-core-2.0.51 app/values/renalware/gender.rb
renalware-core-2.0.50 app/values/renalware/gender.rb
renalware-core-2.0.48 app/values/renalware/gender.rb
renalware-core-2.0.47 app/values/renalware/gender.rb
renalware-core-2.0.46 app/values/renalware/gender.rb
renalware-core-2.0.45 app/values/renalware/gender.rb
renalware-core-2.0.44 app/values/renalware/gender.rb
renalware-core-2.0.43 app/values/renalware/gender.rb
renalware-core-2.0.42 app/values/renalware/gender.rb
renalware-core-2.0.41 app/values/renalware/gender.rb