Class: LLT::FormBuilder::StemHashParser
- Inherits:
-
Object
- Object
- LLT::FormBuilder::StemHashParser
- Includes:
- Helpers::Normalizer
- Defined in:
- lib/llt/form_builder/helpers/stem_hash_parser.rb
Constant Summary collapse
- IRE_DEFAULTS =
%i{ irregular_praesens irregular_praesens_infinitivum irregular_ppa irregular_gerund irregular_gerundive }
- FERRE_DEFAULTS =
%i{ irregular_praesens irregular_praesens_infinitivum ppa gerund gerundive }
- OTHER_DEFAULTS =
%i{ irregular_praesens irregular_praesens_infinitivum }
- REG_DEFAULTS =
%i{ praesens praesens_infinitivum ppa gerund gerundive }
- PERF_DEFAULTS =
%i{ perfectum perfectum_infinitivum }
- PPP_DEFAULTS =
%i{ ppp fp supinum }
Instance Method Summary collapse
- #adapted_stem ⇒ Object
- #add(hash) ⇒ Object
- #add_unchanged ⇒ Object
- #add_with_new_inflection_class(*infl_classes) ⇒ Object
- #add_with_new_type(*types) ⇒ Object
-
#adjective_changes ⇒ Object
Adjective Changes #######.
- #attributes ⇒ Object
- #comparativus? ⇒ Boolean
- #default_verbal_types(m, ext, tmp) ⇒ Object
- #extension_mapping(ext) ⇒ Object
- #inflection_class ⇒ Object
-
#initialize(stem_hashes) ⇒ StemHashParser
constructor
A new instance of StemHashParser.
- #invalid_options? ⇒ Boolean
- #irregular_adverb_building? ⇒ Boolean
- #irregular_verb? ⇒ Boolean
- #kind_of_quisque ⇒ Object
- #mood_mapping(mood) ⇒ Object
- #mood_term(val) ⇒ Object
- #orig_type ⇒ Object
- #parse ⇒ Object
- #parse_verb(category, var) ⇒ Object
-
#perfectum_changes ⇒ Object
Perfectum Changes #######.
- #perfectum_defaults ⇒ Object
-
#ppp_changes ⇒ Object
PPP Changes #######.
- #ppp_defaults ⇒ Object
-
#praesens_changes ⇒ Object
Praesens Changes #######.
- #praesens_defaults ⇒ Object
-
#pronoun_changes ⇒ Object
Pronoun Changes #########.
- #tempus_mapping(tmp) ⇒ Object
-
#type ⇒ Object
General Helper #######.
- #verb_defaults ⇒ Object
-
#verbal_changes ⇒ Object
Verb Helpers #######.
Constructor Details
#initialize(stem_hashes) ⇒ StemHashParser
Returns a new instance of StemHashParser.
7 8 9 10 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 7 def initialize(stem_hashes) @stem_hashes = stem_hashes.map { |h| normalize_args(h) } @result = [] end |
Instance Method Details
#adapted_stem ⇒ Object
74 75 76 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 74 def adapted_stem @hash[:stem].sub(/ior$/, "ius") end |
#add(hash) ⇒ Object
133 134 135 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 133 def add(hash) @result << hash end |
#add_unchanged ⇒ Object
137 138 139 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 137 def add_unchanged @result << @hash end |
#add_with_new_inflection_class(*infl_classes) ⇒ Object
127 128 129 130 131 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 127 def add_with_new_inflection_class(*infl_classes) infl_classes.each do |infl_cl| @result << @hash.merge(inflection_class: infl_cl) end end |
#add_with_new_type(*types) ⇒ Object
121 122 123 124 125 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 121 def add_with_new_type(*types) types.each do |type| @result << @hash.merge(type: type) end end |
#adjective_changes ⇒ Object
Adjective Changes #######
66 67 68 69 70 71 72 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 66 def adjective_changes add_unchanged unless irregular_adverb_building? || stem = comparativus? ? adapted_stem : @hash[:stem] add(@hash.merge(stem: stem, type: :adverb)) unless irregular_adverb_building? end end |
#attributes ⇒ Object
152 153 154 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 152 def attributes %i{ extension modus tempus }.map { |attr| @opts[attr] } end |
#comparativus? ⇒ Boolean
82 83 84 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 82 def comparativus? @hash[:comparatio] == :comparativus end |
#default_verbal_types(m, ext, tmp) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 191 def default_verbal_types(m, ext, tmp) unless m || ext if tmp || @opts[:finite] add_with_new_type(verb_defaults.first) # praesens or perfectum else add_with_new_type(*verb_defaults) end end end |
#extension_mapping(ext) ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 206 def extension_mapping(ext) case ext when "nd" then [:gerund, :gerundive] when /^nt?$/ then :ppa when "ur" then :fp else orig_type end end |
#inflection_class ⇒ Object
117 118 119 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 117 def inflection_class @hash[:inflection_class] end |
#invalid_options? ⇒ Boolean
86 87 88 89 90 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 86 def if @opts @opts[:sexus] || @opts[:numerus] || @opts[:casus] end end |
#irregular_adverb_building? ⇒ Boolean
78 79 80 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 78 def irregular_adverb_building? @hash[:irregular_adverb] end |
#irregular_verb? ⇒ Boolean
161 162 163 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 161 def irregular_verb? @hash[:inflection_class].kind_of?(Symbol) # all irregulars are given as symbol, regulars come as Fixnum end |
#kind_of_quisque ⇒ Object
106 107 108 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 106 def kind_of_quisque /quisque/ =~ inflection_class end |
#mood_mapping(mood) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 215 def mood_mapping(mood) case type when :praesens case mood when mood_term(:participle) then :ppa when mood_term(:infinitive) then :praesens_infinitivum when mood_term(:gerund) then :gerund when mood_term(:gerundive) then :gerundive else orig_type end when :perfectum case mood when mood_term(:infinitive) then :perfectum_infinitivum else type end when :ppp case mood when mood_term(:participle) then [:ppp, :fp] when mood_term(:supinum) then :supinum else type end end end |
#mood_term(val) ⇒ Object
239 240 241 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 239 def mood_term(val) t.value_term_for(:modus, val) end |
#orig_type ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 254 def orig_type if irregular_verb? verb_defaults.find { |default| default.match(/#{type}$/) } else type end end |
#parse ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 12 def parse @stem_hashes.each do |hash| @hash = hash @opts = hash[:options] m = "#{type}_changes" if respond_to?(m) send(m) else add_unchanged end end @result end |
#parse_verb(category, var) ⇒ Object
201 202 203 204 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 201 def parse_verb(category, var) return unless var add_with_new_type(*send("#{category}_mapping", var)) end |
#perfectum_changes ⇒ Object
Perfectum Changes #######
42 43 44 45 46 47 48 49 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 42 def perfectum_changes verbal_changes do |ext, m, tmp| parse_verb(:mood, m) parse_verb(:extension, ext) default_verbal_types(m, ext, tmp) end end |
#perfectum_defaults ⇒ Object
182 183 184 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 182 def perfectum_defaults PERF_DEFAULTS end |
#ppp_changes ⇒ Object
PPP Changes #######
54 55 56 57 58 59 60 61 62 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 54 def ppp_changes verbal_changes do |ext, m, tmp| parse_verb(:extension, ext) parse_verb(:mood, m) parse_verb(:tempus, tmp) add_with_new_type(*verb_defaults) unless m || ext || tmp end end |
#ppp_defaults ⇒ Object
187 188 189 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 187 def ppp_defaults PPP_DEFAULTS end |
#praesens_changes ⇒ Object
Praesens Changes #######
31 32 33 34 35 36 37 38 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 31 def praesens_changes verbal_changes do |ext, m, tmp| parse_verb(:extension, ext) parse_verb(:mood, m) default_verbal_types(m, ext, tmp) end end |
#praesens_defaults ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 169 def praesens_defaults if irregular_verb? case @hash[:inflection_class] when :ire then IRE_DEFAULTS when :ferre then FERRE_DEFAULTS else OTHER_DEFAULTS end else REG_DEFAULTS end end |
#pronoun_changes ⇒ Object
Pronoun Changes #########
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 95 def pronoun_changes if kind_of_quisque && @opts[:ending] == "is" # whether quisque or quisque_s arrive - always return both base_infl = inflection_class.to_s.match(/([a-z]+)_?/)[1] types = [base_infl, base_infl + "_s"].map(&:to_sym) add_with_new_inflection_class(*types) else add_unchanged end end |
#tempus_mapping(tmp) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 243 def tempus_mapping(tmp) # more to come, especially for praesens stem probably (ppa? gerundive?) case type when :ppp case tmp when t.fut then :fp when t.pf then :ppp end end end |
#type ⇒ Object
General Helper #######
113 114 115 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 113 def type @hash[:type] end |
#verb_defaults ⇒ Object
157 158 159 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 157 def verb_defaults send("#{type}_defaults") end |
#verbal_changes ⇒ Object
Verb Helpers #######
144 145 146 147 148 149 150 |
# File 'lib/llt/form_builder/helpers/stem_hash_parser.rb', line 144 def verbal_changes if @opts yield(*attributes) else add_with_new_type(*verb_defaults) end end |