Module: Inflectionable

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/inflectionable.rb

Instance Method Summary collapse

Instance Method Details

#create_default_inflectionalObject



61
62
63
64
65
66
# File 'app/models/concerns/inflectionable.rb', line 61

def create_default_inflectional
  # ensure a matching inflectional exists
  if value && inflectionals.where(:value => value).none?
    inflectionals.create(:value => value)
  end
end

#endingsObject



15
16
17
# File 'app/models/concerns/inflectionable.rb', line 15

def endings
  Inflectional::Base.for_language_and_code(language, inflectional_code)
end

#generate_inflectionals!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/concerns/inflectionable.rb', line 19

def generate_inflectionals!
  return send(Inflectional::Base.name.to_relation_name) if base_form.blank?

  converted_literal_form = Iqvoc::Origin.new(value).to_s

  diff = Iqvoc::Origin.new(converted_literal_form).sanitize_base_form.to_s.size - base_form.size

  unless base_form.blank?
    new_base_form = converted_literal_form[0..(base_form.length-1)]
  end

  Rails.logger.debug "converted_literal_form => #{converted_literal_form} (#{converted_literal_form.size}) |
  base_form => #{base_form} (#{base_form.size}) |
  new_base_form => #{new_base_form} |
  value => #{value} (#{value.size}) |
  diff => #{diff}"

  endings.each do |ending|
    value = ending == "." ? new_base_form : (new_base_form + ending.downcase)
    send(Inflectional::Base.name.to_relation_name).create!(:value => value)
  end

  self.base_form = new_base_form
  save(:validate => false)

  inflectionals
end

#inflectionals_attributes=(str) ⇒ Object



47
48
49
# File 'app/models/concerns/inflectionable.rb', line 47

def inflectionals_attributes=(str)
  @inflectionals_attributes = str.split("\r\n")
end

#overwrite_inflectionals!Object



51
52
53
54
55
56
57
58
59
# File 'app/models/concerns/inflectionable.rb', line 51

def overwrite_inflectionals!
  return unless inflectionals_attributes
  transaction do
    inflectionals.delete_all
    inflectionals_attributes.each do |value|
      inflectionals.create!(:value => value)
    end
  end
end