Module: Vivlio::Starter::CLI::PreProcessCommands::DataRender::Singularize

Defined in:
lib/vivlio/starter/cli/pre_process/data_render/singularize.rb

Overview

英単語の複数形→単数形変換モジュール

Class Method Summary collapse

Class Method Details

.call(word) ⇒ String

複数形の英単語を単数形に変換する

Parameters:

  • word (String)

    変換対象の単語

Returns:

  • (String)

    単数形の単語



31
32
33
34
35
36
37
38
39
# File 'lib/vivlio/starter/cli/pre_process/data_render/singularize.rb', line 31

def call(word)
  case word.to_s
  in /\A(.+)ies\z/              then "#{::Regexp.last_match(1)}y" # categories → category
  in /\A(.+)([sxz]|ch|sh)es\z/  then "#{::Regexp.last_match(1)}#{::Regexp.last_match(2)}" # branches → branch
  in /\A(.+)ves\z/              then "#{::Regexp.last_match(1)}f"       # shelves → shelf
  in /\A(.+)s\z/                then ::Regexp.last_match(1)             # elements → element
  else word.to_s # data, sheep(不変)
  end
end