class Genderize::Gender

Constants

ABR_KEY_NAME_MAPPING

Maps the gender abbreviation name to the full name for translation keys

Attributes

abbr[R]

Public Class Methods

new(abbr) click to toggle source
# File lib/genderize/gender.rb, line 12
def initialize(abbr)
  unless abbr.blank? or abbr.to_s =~ /\A(f|m|n|female|male|non[ -_]?binary)\Z/i
    raise "Invalid abbreviation: '#{abbr}'"
  end
  @abbr = abbr.blank? ? '' : abbr.to_s.first.downcase
end

Public Instance Methods

==(val) click to toggle source
# File lib/genderize/gender.rb, line 63
def ==(val)
  abbr.to_s == val.to_s
end
blank?() click to toggle source
# File lib/genderize/gender.rb, line 55
def blank?
  abbr == ""
end
capital_abbr() click to toggle source
# File lib/genderize/gender.rb, line 39
def capital_abbr
  abbr.capitalize
end
casual() click to toggle source
# File lib/genderize/gender.rb, line 35
def casual
  @casual ||= translation_for("casual")
end
female?() click to toggle source
# File lib/genderize/gender.rb, line 47
def female?
  abbr == 'f'
end
male?() click to toggle source
# File lib/genderize/gender.rb, line 43
def male?
  abbr == 'm'
end
name() click to toggle source
# File lib/genderize/gender.rb, line 19
def name
  @name ||= translation_for("name")
end
non_binary?() click to toggle source
# File lib/genderize/gender.rb, line 51
def non_binary?
  abbr == 'n'
end
object() click to toggle source
# File lib/genderize/gender.rb, line 27
def object
  @object ||= translation_for("object")
end
possessive() click to toggle source
# File lib/genderize/gender.rb, line 31
def possessive
  @possessive ||= translation_for("possessive")
end
subject() click to toggle source
# File lib/genderize/gender.rb, line 23
def subject
  @subject ||= translation_for("subject")
end
to_s() click to toggle source
# File lib/genderize/gender.rb, line 59
def to_s
  abbr
end

Private Instance Methods

translation_for(key) click to toggle source
# File lib/genderize/gender.rb, line 71
def translation_for(key)
  I18n.t("genderize.#{key}.#{ABR_KEY_NAME_MAPPING[abbr]}")
end