Sha256: a8bc7e222333517239e5d5e90979782aa6960381c6bddc6f6b3d0438d03c5a72
Contents?: true
Size: 656 Bytes
Versions: 113
Compression:
Stored size: 656 Bytes
Contents
class PigLatin def self.translate(phrase) phrase.split(' ').map do |word| PigLatin.new(word).translate end.join(' ') end def initialize(word) @word = word.downcase.gsub(/[^a-z]/, '') end def translate return (word + 'ay') if it_starts_with_vowel_sound? start, remainder = parse_initial_consonant_sound_and_remainder remainder + start + 'ay' end private attr_reader :word def it_starts_with_vowel_sound? word.match /\A([aeiou]|y[^aeiou]|xr)/ end def parse_initial_consonant_sound_and_remainder word.scan(/\A([^aeiou]?qu|[^aeiou]+)(.*)/).first end end module BookKeeping VERSION = 1 end
Version data entries
113 entries across 113 versions & 1 rubygems