Sha256: ddf4497b34ba2071e76596d4663d31394179909964d2a9ffe141d95ec792cd60

Contents?: true

Size: 795 Bytes

Versions: 21

Compression:

Stored size: 795 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module BetterRecord
  module Gender
    ENUM = {
      f: 'F',
      F: 'F',
      female: 'F',
      Female: 'F',
      m: 'M',
      M: 'M',
      male: 'M',
      Male: 'M',
      u: 'U',
      U: 'U',
      unknown: 'U',
      Unknown: 'U'
    }.freeze

    def self.convert_to_gender(value)
      case value.to_s
      when /^[Ff]/
        'F'
      when /^[Mm]/
        'M'
      else
        'U'
      end
    end

    module TableDefinition
      def gender(*args, **opts)
        args.each do |name|
          column name, :gender, **opts
        end
      end
    end

    class Type < BetterRecord::CustomType
      def self.normalize_type_value(value)
        BetterRecord::Gender.convert_to_gender(value)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
better_record-0.25.2 lib/better_record/gender.rb
better_record-0.25.1 lib/better_record/gender.rb
better_record-0.25.0 lib/better_record/gender.rb
better_record-0.24.4 lib/better_record/gender.rb
better_record-0.24.3 lib/better_record/gender.rb
better_record-0.23.7 lib/better_record/gender.rb
better_record-0.23.6 lib/better_record/gender.rb
better_record-0.23.5 lib/better_record/gender.rb
better_record-0.23.4 lib/better_record/gender.rb
better_record-0.23.3 lib/better_record/gender.rb
better_record-0.22.9 lib/better_record/gender.rb
better_record-0.22.8 lib/better_record/gender.rb
better_record-0.22.7 lib/better_record/gender.rb
better_record-0.22.6 lib/better_record/gender.rb
better_record-0.22.5 lib/better_record/gender.rb
better_record-0.22.4 lib/better_record/gender.rb
better_record-0.22.3 lib/better_record/gender.rb
better_record-0.21.3 lib/better_record/gender.rb
better_record-0.22.2 lib/better_record/gender.rb
better_record-0.22.0 lib/better_record/gender.rb