Sha256: b90a96b5a437e1a151e6f495726762811c560c256dba32badbb2cf9e9e19b5e3

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8

require 'ffaker/name'

module Faker
  module NameDA
    include Faker::Name

    extend ModuleUtils
    extend self

    def name gender = :any
      case gender
      when :any then any_name
      when :male then male_name
      when :female then female_name
      else
        raise ArgumentError, "Invalid gender, must be one of :any, :male, :female"
      end
    end

    def any_name
      case rand(8)
      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

    def male_name
      fname = first_name :male
      case rand(8)
      when 0    then "#{prefix} #{fname} #{last_name}"
      when 1..2 then "#{fname} #{last_name} #{last_name}"
      else           "#{fname} #{last_name}"
      end
    end

    def female_name
      fname = first_name :female
      case rand(8)
      when 0    then "#{prefix} #{fname} #{last_name}"
      when 1..2 then "#{fname} #{last_name} #{last_name}"
      else           "#{fname} #{last_name}"
      end
    end

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

    def last_name
      LAST_NAMES.rand
    end

    def prefix
      PREFIXES.rand
    end

    PREFIXES = k %w(Hr. Fr. Dr. Prof.)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffaker-1.30.0 lib/ffaker/name_da.rb
ffaker-1.25.0 lib/ffaker/name_da.rb
ffaker-1.24.0 lib/ffaker/name_da.rb
ffaker-1.23.0 lib/ffaker/name_da.rb
ffaker-1.22.1 lib/ffaker/name_da.rb
ffaker-1.22.0 lib/ffaker/name_da.rb