Sha256: bbb4e9704decf5b780a5c933c866cdebd87201804e48b36dc7a5b5c20f50c64c
Contents?: true
Size: 964 Bytes
Versions: 1
Compression:
Stored size: 964 Bytes
Contents
require File.expand_path('../examples_helper', File.dirname(__FILE__)) Wukong.processor :pig_latinize do CONSONANTS = "bcdfghjklmnpqrstvwxz" UPPERCASE = /^[A-Z]/ # Regular expression to identify the parts of a pig-latin-izable word PIG_LATIN_WORD_RE = %r{ \b # word boundary ([#{CONSONANTS}]*) # all initial consonants ([\w\']+) # remaining word characters }xi def latinize(line) line.gsub(PIG_LATIN_WORD_RE) do init, rest = [$1, $2] init = 'w' if init.blank? rest.capitalize! if init =~ UPPERCASE "#{rest}#{init.downcase}ay" end end def process(line) emit latinize(line) end end ExampleUniverse.dataflow(:pig_latin) do input :default, file_source(Pathname.path_to(:data, 'text/gift_of_the_magi.txt')) output :default, file_sink( Pathname.path_to(:tmp, 'text/pig_latin/gift_of_the_magi.txt')) input(:default) > pig_latinize > output(:default) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wukong-3.0.0.pre | examples/text/pig_latin.rb |