Module: Utilities::Latin

Defined in:
lib/utilities/latin.rb

Constant Summary collapse

ENDINGS =

rubocop:disable Style/StringHashKeys

{
  'er' => %w{ra era rum},
  'or' => %w{rix},
  'ae' => %w{ei a e i},
  'anum' => %w{ensis},
  'major' => %w{majus},
  's' => %w{es is us},
  'm' => %w{um}
}.freeze

Class Method Summary collapse

Class Method Details

.all_endingsArray

An Array of all endings sorted by length, longest first

Returns:

  • (Array)


24
25
26
# File 'lib/utilities/latin.rb', line 24

def self.all_endings
  (ENDINGS.keys + ENDINGS.values).flatten.sort{|a,b| b.length <=> a.length}
end

.root(name) ⇒ Boolean

Parameters:

  • name (String)

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
# File 'lib/utilities/latin.rb', line 30

def self.root(name)
  return false if name.nil? || name.class != String
  self.all_endings.each do |e|
    if name =~ /(?<s>.*)#{e}\Z/
      return $~[:s]
    end
  end
  false
end

.same_root_name?(name1, name2) ⇒ Boolean

Parameters:

  • name1 (String)
  • name2 (String)

Returns:

  • (Boolean)


18
19
20
# File 'lib/utilities/latin.rb', line 18

def self.same_root_name?(name1, name2)
  return false if (name1.length - name2.length).abs > 1
end