Sha256: aa7ca17079f15f5c267c6a5eba3eece12068d72ff98f77e761c509b066ee803d

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'ffaker/name'

module FFaker
  module NameDA
    include FFaker::Name

    extend ModuleUtils
    extend self

    PREFIXES = %w[Hr. Fr. Dr. Prof.].freeze

    def name(gender = :any)
      generate_name(first_name(gender))
    end

    def any_name
      name(:any)
    end

    def male_name
      name(:male)
    end

    def female_name
      name(:female)
    end

    def first_name(gender = :any)
      case gender
      when :any then rand(0..1).zero? ? first_name(:male) : first_name(:female)
      when :male then fetch_sample(MALE_FIRST_NAMES)
      when :female then fetch_sample(FEMALE_FIRST_NAMES)
      else
        raise ArgumentError, 'Invalid gender, must be one of :any, :male, :female'
      end
    end

    def last_name
      fetch_sample(LAST_NAMES)
    end

    def prefix
      fetch_sample(PREFIXES)
    end

    private

    def generate_name(first_name)
      case rand(0..7)
      when 0    then "#{prefix} #{first_name} #{last_name}"
      when 1..2 then "#{first_name} #{last_name} #{last_name}"
      else           "#{first_name} #{last_name}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffaker-2.17.0 lib/ffaker/name_da.rb
ffaker-2.16.0 lib/ffaker/name_da.rb
ffaker-2.15.0 lib/ffaker/name_da.rb
ffaker-2.14.0 lib/ffaker/name_da.rb
ffaker-2.13.0 lib/ffaker/name_da.rb
ffaker-2.12.0 lib/ffaker/name_da.rb