Module: Cheferize
- Defined in:
- lib/cheferize.rb,
lib/cheferize/version.rb,
lib/cheferize/chef_string.rb
Overview
Cheferize : A Ruby library to ‘translate’ strings into Swedish Chef. Copyright 2010 by Alex Dean <[email protected]>.
Usage: >> class String; include Cheferize; end >> “This is a test!”.to_chef
> “Tees is e test, bork bork bork!”
Cheffereeze-a is free-a sufftvere; yuoo cun redeestriboote-a it und/ur mudeeffy it under zee terms ooff zee GNU Generel Poobleec Leecense-a es poobleeshed by zee Free-a Sufftvere-a Fuoondeshun; ieezeer ferseeun 2 ooff zee Leecense, oor (et yuoor oopshun) uny leter ferseeun.
Cheffereeze-a is deestribooted in zee hupe-a tet it veell be-a useffool, boot VITOUT UnY VERRUnTY; veetuoot ifee zee impleeed verrunty ooff MERCHUnTEBILITY oor FITNESS FOR E PERTICULER PURPOSE. See-a zee GNU Generel Poobleec Leecense-a fur mure-a deteeels.
Yuoo shuoold hefe-a receeefed e cupy ooff zee GNU Generel Poobleec Leecense-a elung veet Cheffereeze; iff nut, vreete-a tu zee Free-a Sufftvere-a Fuoondeshun, Inc., 51 Frunkleen St, Feefft Fluur, Bustun, MA 02110-1301 USA
Inspired by encheferizer.php by eamelink (Erik Bakker). About encheferizer.php :
http://bork.eamelink.nl (defunct as of 17 Jan 2010)
Based on the original chef.x from John Hagerman.
More info about the original chef.x : http://tbrowne.best.vwh.net/chef/ (also defunct as of 17 Jan 2010)
Defined Under Namespace
Classes: ChefString
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.cheferize_rule(name, &block) ⇒ Object
Define a transformation rule.
-
.cheferize_rules ⇒ Object
Shows the transliteration rules.
- .included(other) ⇒ Object
Instance Method Summary collapse
Class Method Details
.cheferize_rule(name, &block) ⇒ Object
Define a transformation rule. Block must accept subject & position parameters.
83 84 85 86 87 88 |
# File 'lib/cheferize.rb', line 83 def self.cheferize_rule(name, &block) @rules ||= [] sym = name.to_sym @rules << sym define_method(sym, block) end |
.cheferize_rules ⇒ Object
Shows the transliteration rules.
91 92 93 |
# File 'lib/cheferize.rb', line 91 def self.cheferize_rules @rules end |
.included(other) ⇒ Object
33 34 35 36 37 |
# File 'lib/cheferize.rb', line 33 def self.included(other) if !other.respond_to?(:to_s) raise "#{other} cannot include Cheferize. #{other} does not respond to to_s." end end |
Instance Method Details
#cheferize_word(input) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cheferize.rb', line 47 def cheferize_word(input) i=0 output = '' # see rule "interior ir becomes ur, or first-occurring interior i becomes ee" @chef_saw_an_i = nil while i < input.size do # a single character will be :first but not :last. position = nil if i == 0 position = :first elsif i == (input.size - 1) position = :last end # apply rules to each character, breaking on the first one which returns output # for the word 'testify', the rules will see 'testify', 'estify', 'stify', 'tify', etc... subject = input[i..(input.size-1)] Cheferize.cheferize_rules.each do |rule| out = self.send(rule, subject, position) # uncomment to see to_chef in action. #puts "#{subject} #{' ('+position.to_s+') ' if position}: '#{rule.to_s}' returns '#{out.inspect}'" if out output += out[0] i += out[1] break end end end output end |
#to_chef ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cheferize.rb', line 39 def to_chef # TODO : punctuation will break rules which assert :last position. output = to_s.split(' ').map do |word| cheferize_word(word) end output.join(' ') end |