Class: LLT::PronounBuilder

Inherits:
DeclinableBuilder show all
Defined in:
lib/llt/form_builder/pronoun_builder.rb

Constant Summary collapse

INDICES_OF_CUM_WITH_QUI =

quo quibus qua quibus quo quibus

[5, 11, 17, 23, 29, 35]
PRON_TYPE =
pt.each_with_object({}) do |(type, infl_classes), h|
  infl_classes.each { |infl_cl| h[infl_cl] = type }
end

Constants inherited from FormBuilder

FormBuilder::VERSION

Instance Attribute Summary

Attributes inherited from DeclinableBuilder

#comparatio, #sexus

Attributes inherited from FormBuilder

#impersonalium

Instance Method Summary collapse

Methods inherited from DeclinableBuilder

#additional_forms, #casus_numerus_sexus_by_index, #er_nominative_possible?, #extended_special_forms, #index_of_ending, #initialize, #irregulars_with_nominative, #new_attributes, #new_form_through_index, #new_special_form, #o_declension_on_ius?, #pronominal_declension?, #proper_vocative, #regular_forms, #regular_o_declension?, #special_ending, #with_replacements

Methods inherited from FormBuilder

#attributes_by_index, build, #cross_indices, #downcase_all_stems, #endings, #endings_attributes, #endings_container, #endings_namespace, #endings_path, #extensions_and_other_signs, #indices_by_ending, #initialize, #keep_given_value, lookup_class, #lookup_indices, #needs_validation?, #new_form, #prefix, #reverse_lookup, #stays_capitalized, #stem_copy, #valid?, #validations, validations, #value_as_index

Constructor Details

This class inherits a constructor from LLT::DeclinableBuilder

Instance Method Details

#computeObject



17
18
19
# File 'lib/llt/form_builder/pronoun_builder.rb', line 17

def compute
  (regular_forms + forms_with_suffix).sort_by(&:index) # quibuscum etc.
end

#corrections(args) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/llt/form_builder/pronoun_builder.rb', line 53

def corrections(args)
  if @options[:ending] == "ic"
    keep_given_value(args, :ending)
  end

  super
end

#default_argsObject



25
26
27
# File 'lib/llt/form_builder/pronoun_builder.rb', line 25

def default_args
  { inflection_class: @inflection_class }
end

#endings_lookup(ending, x) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/llt/form_builder/pronoun_builder.rb', line 29

def endings_lookup(ending, x)
  if ending == "s" && is_or_idem
    x.to_s =~ /^i?s$/
  elsif ending == "ic"
    x.to_s == "id"
  else
    super
  end
end

#form_classObject



102
103
104
# File 'lib/llt/form_builder/pronoun_builder.rb', line 102

def form_class
  constant_by_type(PRON_TYPE[@inflection_class], namespace: LLT::Form)
end

#forms_with_suffixObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/llt/form_builder/pronoun_builder.rb', line 40

def forms_with_suffix
  if @inflection_class == :qui
    indices = INDICES_OF_CUM_WITH_QUI & @lookup_indices
    indices.map { |i| [endings[i], i] }.map do |ending, i|
      casus, numerus, sexus = casus_numerus_sexus_by_index(i)
      ending = ending.to_s
      new_form(ending: ending, casus: casus, numerus: numerus, sexus: sexus, index: i, suffix: "cum")
    end.compact # for forms that don't make it through validation
  else
    []
  end
end

#indicesObject



11
12
13
14
15
# File 'lib/llt/form_builder/pronoun_builder.rb', line 11

def indices
  { casus:   [0, 1, 2, 3, nil, 5],
    numerus: [0, 6],
    sexus:   [0, 12, 24] }
end

#init_keysObject



21
22
23
# File 'lib/llt/form_builder/pronoun_builder.rb', line 21

def init_keys
  %i{ type inflection_class }
end

#is_or_idemObject



85
86
87
# File 'lib/llt/form_builder/pronoun_builder.rb', line 85

def is_or_idem
  @inflection_class == :is || @inflection_class == :idem
end

#validation_rule(args, validator) ⇒ Object

Allows i and e stem for specific forms like ii/ei. If such a form is detected return the validation, in every other case use the default rule.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/llt/form_builder/pronoun_builder.rb', line 64

def validation_rule(args, validator)
  if is_or_idem
    case validator
    when :stem
      c, n, s = %i{ casus numerus sexus }.map { |k| args[k] }

      if n == 2 && ((c == 1 && s == :m) || (c == 3 || c == 6))
        val_values = [args[validator], @options[validator]]
        if val_values.all? { |stem| stem =~ /^[ei]$/ }
          keep_given_value(args, validator)
          # also keep the ending to catch is, iis and eis
          keep_given_value(args, :ending)
          return true # to prevent the super call
        end
      end
    end
  end

  super
end