Module: Gamefic::Grammar::Pronoun

Defined in:
lib/gamefic/grammar/pronoun.rb

Overview

Methods to select pronouns based on an entity’s attributes, such as gender.

Constant Summary collapse

MAP_KEYS =
%i[subjective objective possessive reflexive].freeze
MAPS =
{
  [1, :singular] => Hash[MAP_KEYS.zip(%w[I me my myself])],
  [2, :singular] => Hash[MAP_KEYS.zip(%w[you you your yourself])],
  [3, :singular] => Hash[MAP_KEYS.zip(%w[it it its itself])],
  [3, :singular, :male] => Hash[MAP_KEYS.zip(%w[he him his himself])],
  [3, :singular, :female] => Hash[MAP_KEYS.zip(%w[she her her herself])],
  [3, :singular, :other] => Hash[MAP_KEYS.zip(%w[they them their themselves])],
  [3, :singular, :neutral] => Hash[MAP_KEYS.zip(%w[it it its itself])],
  [1, :plural] => Hash[MAP_KEYS.zip(%w[we us our ourselves])],
  [2, :plural] => Hash[MAP_KEYS.zip(%w[you you your yourselves])],
  [3, :plural] => Hash[MAP_KEYS.zip(%w[they them their themselves])]
}.freeze

Class Method Summary collapse

Class Method Details

.objective(entity) ⇒ String Also known as: them

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


46
47
48
# File 'lib/gamefic/grammar/pronoun.rb', line 46

def objective(entity)
  prounoun_map(entity)[:objective]
end

.objective_(entity) ⇒ String Also known as: them_

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


53
54
55
# File 'lib/gamefic/grammar/pronoun.rb', line 53

def objective_(entity)
  objective(entity).cap_first
end

.possessive(entity) ⇒ String Also known as: their

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


60
61
62
# File 'lib/gamefic/grammar/pronoun.rb', line 60

def possessive(entity)
  prounoun_map(entity)[:possessive]
end

.possessive_(entity) ⇒ String Also known as: their_

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


67
68
69
# File 'lib/gamefic/grammar/pronoun.rb', line 67

def possessive_(entity)
  possessive(entity).cap_first
end

.prounoun_map(entity) ⇒ Hash

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (Hash)


90
91
92
93
94
# File 'lib/gamefic/grammar/pronoun.rb', line 90

def prounoun_map(entity)
  plurality = (entity.plural? ? :plural : :singular)
  MAPS[[entity.person || 3, plurality, entity.gender]] ||
    MAPS[[entity.person || 3, plurality]]
end

.reflexive(entity) ⇒ String Also known as: themselves, themself

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


74
75
76
# File 'lib/gamefic/grammar/pronoun.rb', line 74

def reflexive(entity)
  prounoun_map(entity)[:reflexive]
end

.reflexive_(entity) ⇒ String Also known as: themselves_, themself_

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


82
83
84
# File 'lib/gamefic/grammar/pronoun.rb', line 82

def reflexive_(entity)
  reflexive(entity).cap_first
end

.subjective(entity) ⇒ String Also known as: they, he, she

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


28
29
30
# File 'lib/gamefic/grammar/pronoun.rb', line 28

def subjective(entity)
  prounoun_map(entity)[:subjective]
end

.subjective_(entity) ⇒ String Also known as: they_, he_, she_

Parameters:

  • entity (#person, #plural?, #gender)

Returns:

  • (String)


37
38
39
# File 'lib/gamefic/grammar/pronoun.rb', line 37

def subjective_(entity)
  subjective(entity).cap_first
end