Module: LLT::Helpers::Terminology

Defined in:
lib/llt/helpers/terminology.rb

Constant Summary collapse

DEFAULT_FORMAT =
{ casus:   :numeric,
numerus: :numeric,
tempus:  :abbr,
sexus:   :abbr,
modus:   :abbr,
type:    :full,
genus:   :abbr,
persona: :numeric }
NORM_VALUES =
{ casus:   [[:nom, :nominativus], [:gen, :genetivus], [:dat, :dativus], [:acc, :accusativus], [:voc, :vocativus], [:abl, :ablativus]],
                numerus: [[:sg, :singularis], [:pl, :pluralis]],
                tempus:  [[:pr, :praesens], [:impf, :imperfectum], [:fut, :futurum], [:pf, :perfectum], [:pqpf, :plusquamperfectum], [:fut_ex, :futurum_exactum]],
                sexus:   [[:m, :masculinum], [:f, :femininum], [:n, :neutrum]],
                modus:   [[:ind, :indicativus], [:con, :coniunctivus], [:imp, :imperativum], [:part, :participium], [:inf, :infinitivum], [:gerundium, :gerundium], [:gerundivum, :gerundivum]],
                type:    [[:noun, :noun], [:adj, :adjective], [:verb, :verb]],#, [:gerundive, :gerundive], [:gerund, :gerund]],
                genus:   [[:act, :activum], [:pass, :passivum]],
                persona: [[:first, :first], [:second, :second], [:third, :third]]
}
KEY_TABLE =
kt.each_with_object({}) do |(norm_term, terms), h|
  terms.each { |term| h[term] = norm_term }
end
VALUE_TABLE =
vt.each_with_object({}) do |(key_term, hash), h|
  nh = hash.each_with_object({}) do |(norm_term, values), nested_h|
    values.each { |val| nested_h[val] = norm_term }
  end
  h[key_term] = nh
end
FULL_TABLE =
KEY_TABLE.merge(VALUE_TABLE.values.inject({}) { |new, old| new.merge(old) })

Class Method Summary collapse

Class Method Details

.camelcased(str) ⇒ Object



133
134
135
# File 'lib/llt/helpers/terminology.rb', line 133

def self.camelcased(str)
  str.to_s.split("_").map(&:capitalize).join
end

.casusObject



72
73
74
# File 'lib/llt/helpers/terminology.rb', line 72

def casus
  :casus
end

.create_three_way_getter_methods(abbr, full, i, type) ⇒ Object

Convenience Methods



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/llt/helpers/terminology.rb', line 119

def self.create_three_way_getter_methods(abbr, full, i, type)
  class_eval <<-STR
    def #{full}(arg = :#{DEFAULT_FORMAT[type]})
      case arg
      when :numeric then #{i + 1}
      when :abbr    then :#{abbr}
      when :full    then :#{full}
      when :camelcase then :#{camelcased(full)}
      end
    end
    alias :#{abbr} :#{full}
  STR
end

.deponensObject



104
105
106
# File 'lib/llt/helpers/terminology.rb', line 104

def deponens
  :deponens
end

.genusObject



96
97
98
# File 'lib/llt/helpers/terminology.rb', line 96

def genus
  :genus
end

.inflection_classObject

Keywords



64
65
66
# File 'lib/llt/helpers/terminology.rb', line 64

def inflection_class
  :inflection_class
end

.inflection_class_number_as_string?(key, value) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/llt/helpers/terminology.rb', line 30

def inflection_class_number_as_string?(key, value)
  key == inflection_class && value.kind_of?(String) && value.match(/^\d*$/)
end

.key_term_for(key) ⇒ Object

rename, scrap term



10
11
12
# File 'lib/llt/helpers/terminology.rb', line 10

def key_term_for(key)
  KEY_TABLE[key.to_sym]
end

.method_missing(meth, *args, &blk) ⇒ Object



52
53
54
# File 'lib/llt/helpers/terminology.rb', line 52

def method_missing(meth, *args, &blk)
  meth
end

.modusObject



92
93
94
# File 'lib/llt/helpers/terminology.rb', line 92

def modus
  :modus
end

.noeObject



88
89
90
# File 'lib/llt/helpers/terminology.rb', line 88

def noe
  :number_of_endings
end

.norm_values_for(key_term, format: ) ⇒ Object



48
49
50
# File 'lib/llt/helpers/terminology.rb', line 48

def norm_values_for(key_term, format: DEFAULT_FORMAT[key_term])
  NORM_VALUES[key_term].map { |values| send(values.first, format) }
end

.numerusObject



80
81
82
# File 'lib/llt/helpers/terminology.rb', line 80

def numerus
  :numerus
end

.personaObject



100
101
102
# File 'lib/llt/helpers/terminology.rb', line 100

def persona
  :persona
end

.sexusObject



84
85
86
# File 'lib/llt/helpers/terminology.rb', line 84

def sexus
  :sexus
end

.tempusObject



68
69
70
# File 'lib/llt/helpers/terminology.rb', line 68

def tempus
  :tempus
end

.term_for(key) ⇒ Object



5
6
7
# File 'lib/llt/helpers/terminology.rb', line 5

def term_for(key)
  FULL_TABLE[key.to_sym]
end

.to_aryObject

implement to_ary everytime you do crazy method_missing stuff. #flatten will bite you otherwise!



58
59
60
# File 'lib/llt/helpers/terminology.rb', line 58

def to_ary
  nil
end

.typeObject



76
77
78
# File 'lib/llt/helpers/terminology.rb', line 76

def type
  :type
end

.val_to_sym_or_integer(val) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/llt/helpers/terminology.rb', line 34

def val_to_sym_or_integer(val)
  # Normalizes strings to symbols or integers, but leaves fixnums intact
  case val
  when /^\d*$/ then val.to_i
  when String  then val.to_sym
  else val
  end
end

.value_term_for(key, value) ⇒ Object Also known as: value_for



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/llt/helpers/terminology.rb', line 14

def value_term_for(key, value)
  t = VALUE_TABLE[key]
  if t.nil?
    # tries to normalize the key
    k = key_term_for(key)

    # hacky solution to normalize inflection class integers
    return value.to_i if inflection_class_number_as_string?(key, value)

    t = VALUE_TABLE[k]
    return value unless t
  end
  t[val_to_sym_or_integer(value)] || value
end

.values_for(key_term, exclude: nil) ⇒ Object



43
44
45
46
# File 'lib/llt/helpers/terminology.rb', line 43

def values_for(key_term, exclude: nil)
  v = VALUE_TABLE[key_term_for(key_term)]
  v ? v.keys : []
end