Sha256: d25fef891ca3102935a7ffd452eb12d99dc76c5eea677c46464cbf46e0054f34

Contents?: true

Size: 1010 Bytes

Versions: 2

Compression:

Stored size: 1010 Bytes

Contents

module Genderize
  class Gender
  
    include I18n

    attr_reader :name, :abbr, :subject, :object, :possessive, :casual

    def initialize(abbr)
      raise "Invalid abbreviation" unless abbr.to_s =~ /\A(f|m)\Z/i
      @abbr = abbr.downcase
      @male = self.abbr == 'm'
      @name = male? ? t("name") : t("name", "feminine")
    
      # pronouns
      @subject    = male? ? t("subject") : t("subject", "feminine")
      @object     = male? ? t("object") : t("object", "feminine")
      @possessive = male? ? t("possessive") : t("possessive", "feminine")
    
      # Other forms
      @casual     = male? ? t("casual") : t("casual", "feminine")
    end
  
    def capital_abbr
      abbr.capitalize
    end
  
    def male?
      @male
    end
  
    def female?
      !male?
    end
  
    def to_s
      @abbr
    end
  
    def ==(val)
      to_s == val.to_s
    end
  
    private
  
    def t(attribute, gender = "masculine")
      I18n.t("genderize.#{attribute}.#{gender}")
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genderize-0.0.2 lib/genderize/gender.rb
genderize-0.0.1 lib/genderize/gender.rb