cheferize 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9fa03403afe8b4ffb4e8497a31e6cc0bbf7437c0
4
+ data.tar.gz: d60518b042be9e1a98a79115a8700aaabf8af5af
5
+ SHA512:
6
+ metadata.gz: d238a4e1b2b52515245c3902b90dbf96ab6047b6076d4007991a04308f2a9e12d003c2dc9ca548fb27f5567592856e88990f5b99bc46e93986928b4cef84343f
7
+ data.tar.gz: 800ba6f46bf60d9c91e7615f924f96b963d7bc0f773420786b6ba858a251744d6094e8e9a983294d42e3d60fea5c8fb64b8c8dc52e368b9c64ce62de761cadac
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /tmp/
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'rspec'
5
+
6
+ # Specify your gem's dependencies in cheferize.gemspec
7
+ gemspec
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Cheferize
2
+
3
+ Cheferize is a Ruby gem which 'translates' strings into Swedish Chef.
4
+
5
+ ## Inspiration / Prior Art
6
+
7
+ Inspired by encheferizer.php by eamelink (Erik Bakker).
8
+
9
+ About encheferizer.php
10
+
11
+ * http://bork.eamelink.nl (defunct as of 17 Jan 2010)
12
+ * Based on the original chef.x from John Hagerman.
13
+ * More info about the original chef.x : http://tbrowne.best.vwh.net/chef/ (also defunct as of 17 Jan 2010)
14
+
15
+ ## Build Status
16
+
17
+ [![Build Status](https://travis-ci.org/alexdean/cheferize.svg?branch=master)](https://travis-ci.org/alexdean/cheferize)
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'cheferize'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install cheferize
34
+
35
+ ## Usage
36
+
37
+ ```
38
+ >> class String; include Cheferize; end
39
+ >> "This is a test!".to_chef
40
+ => "Tees is e test, bork bork bork!"
41
+ ```
42
+
43
+ ## License
44
+
45
+ Cheffereeze-a is free-a sufftvere; yuoo cun redeestriboote-a it und/ur mudeeffy
46
+ it under zee terms ooff zee GNU Generel Poobleec Leecense-a es poobleeshed by
47
+ zee Free-a Sufftvere-a Fuoondeshun; ieezeer ferseeun 2 ooff zee Leecense, oor
48
+ (et yuoor oopshun) uny leter ferseeun.
49
+
50
+ Cheffereeze-a is deestribooted in zee hupe-a tet it veell be-a useffool,
51
+ boot VITOUT UnY VERRUnTY; veetuoot ifee zee impleeed verrunty ooff
52
+ MERCHUnTEBILITY oor FITNESS FOR E PERTICULER PURPOSE. See-a zee
53
+ GNU Generel Poobleec Leecense-a fur mure-a deteeels.
54
+
55
+ Yuoo shuoold hefe-a receeefed e cupy ooff zee GNU Generel Poobleec Leecense-a
56
+ elung veet Cheffereeze; iff nut, vreete-a tu zee Free-a Sufftvere-a
57
+ Fuoondeshun, Inc., 51 Frunkleen St, Feefft Fluur, Bustun, MA 02110-1301 USA
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alexdean/cheferize.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cheferize"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ class String
10
+ include Cheferize
11
+ end
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cheferize.gemspec ADDED
@@ -0,0 +1,25 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cheferize/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cheferize"
8
+ spec.version = Cheferize::VERSION
9
+ spec.authors = ["Alex Dean"]
10
+ spec.email = ["github@mostlyalex.com"]
11
+
12
+ spec.summary = %q{Transliterate strings into Swedish Chef.}
13
+ spec.homepage = "https://github.com/alexdean/cheferize."
14
+
15
+ spec.required_ruby_version = '>= 2.3', '<= 2.7'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,44 @@
1
+ module Cheferize
2
+ # A ChefString provides an additional public method for String. in_same_case_as.
3
+ class ChefString
4
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }
5
+
6
+ def initialize(str)
7
+ @target = str
8
+ end
9
+
10
+ # return target string, transformed into the same case as the first character of target.
11
+ def in_same_case_as(target)
12
+ to_case(@target, get_case(target))
13
+ end
14
+
15
+ def get_case(letter)
16
+ code = letter.codepoints[0]
17
+ if code > 96 && code < 123
18
+ :lower
19
+ elsif code > 64 && code < 91
20
+ :upper
21
+ else
22
+ :non_alpha
23
+ end
24
+ end
25
+
26
+ def to_case(letter, sym)
27
+ case sym
28
+ when :upper
29
+ letter.upcase
30
+ when :lower
31
+ letter.downcase
32
+ else
33
+ letter
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ # proxy any remaining calls to the underlying string.
40
+ def method_missing(name, *args, &block)
41
+ @target.send(name, *args, &block)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Cheferize
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cheferize.rb ADDED
@@ -0,0 +1,282 @@
1
+ require "cheferize/version"
2
+ require "cheferize/chef_string"
3
+
4
+ # Cheferize : A Ruby library to 'translate' strings into Swedish Chef.
5
+ # Copyright 2010 by Alex Dean <github@mostlyalex.com>.
6
+ #
7
+ # Usage:
8
+ # >> class String; include Cheferize; end
9
+ # >> "This is a test!".to_chef
10
+ # => "Tees is e test, bork bork bork!"
11
+ #
12
+ # Cheffereeze-a is free-a sufftvere; yuoo cun redeestriboote-a it und/ur mudeeffy
13
+ # it under zee terms ooff zee GNU Generel Poobleec Leecense-a es poobleeshed by
14
+ # zee Free-a Sufftvere-a Fuoondeshun; ieezeer ferseeun 2 ooff zee Leecense, oor
15
+ # (et yuoor oopshun) uny leter ferseeun.
16
+ #
17
+ # Cheffereeze-a is deestribooted in zee hupe-a tet it veell be-a useffool,
18
+ # boot VITOUT UnY VERRUnTY; veetuoot ifee zee impleeed verrunty ooff
19
+ # MERCHUnTEBILITY oor FITNESS FOR E PERTICULER PURPOSE. See-a zee
20
+ # GNU Generel Poobleec Leecense-a fur mure-a deteeels.
21
+ #
22
+ # Yuoo shuoold hefe-a receeefed e cupy ooff zee GNU Generel Poobleec Leecense-a
23
+ # elung veet Cheffereeze; iff nut, vreete-a tu zee Free-a Sufftvere-a
24
+ # Fuoondeshun, Inc., 51 Frunkleen St, Feefft Fluur, Bustun, MA 02110-1301 USA
25
+ #
26
+ # Inspired by encheferizer.php by eamelink (Erik Bakker).
27
+ # About encheferizer.php :
28
+ # http://bork.eamelink.nl (defunct as of 17 Jan 2010)
29
+ # Based on the original chef.x from John Hagerman.
30
+ # More info about the original chef.x : http://tbrowne.best.vwh.net/chef/ (also defunct as of 17 Jan 2010)
31
+ #
32
+ module Cheferize
33
+ def self.included(other)
34
+ if !other.respond_to?(:to_s)
35
+ raise "#{other} cannot include Cheferize. #{other} does not respond to to_s."
36
+ end
37
+ end
38
+
39
+ def to_chef
40
+ # TODO : punctuation will break rules which assert :last position.
41
+ output = to_s.split(' ').map do |word|
42
+ cheferize_word(word)
43
+ end
44
+ output.join(' ')
45
+ end
46
+
47
+ def cheferize_word(input)
48
+ i=0
49
+ output = ''
50
+ # see rule "interior ir becomes ur, or first-occurring interior i becomes ee"
51
+ @chef_saw_an_i = nil
52
+
53
+ while i < input.size do
54
+ # a single character will be :first but not :last.
55
+ position = nil
56
+ if i == 0
57
+ position = :first
58
+ elsif i == (input.size - 1)
59
+ position = :last
60
+ end
61
+
62
+ # apply rules to each character, breaking on the first one which returns output
63
+ # for the word 'testify', the rules will see 'testify', 'estify', 'stify', 'tify', etc...
64
+ subject = input[i..(input.size-1)]
65
+
66
+ Cheferize.cheferize_rules.each do |rule|
67
+ out = self.send(rule, subject, position)
68
+ # uncomment to see to_chef in action.
69
+ #puts "#{subject} #{' ('+position.to_s+') ' if position}: '#{rule.to_s}' returns '#{out.inspect}'"
70
+ if out
71
+ output += out[0]
72
+ i += out[1]
73
+ break
74
+ end
75
+ end
76
+ end
77
+
78
+ output
79
+ end
80
+
81
+ # Define a transformation rule.
82
+ # Block must accept subject & position parameters.
83
+ def self.cheferize_rule(name, &block)
84
+ @rules ||= []
85
+ sym = name.to_sym
86
+ @rules << sym
87
+ define_method(sym, block)
88
+ end
89
+
90
+ # Shows the transliteration rules.
91
+ def self.cheferize_rules
92
+ @rules
93
+ end
94
+
95
+ # General rules
96
+ #
97
+ # after a replacement occurs, skip to the next source character. (only 1 transformation per letter)
98
+ # if a multi-character test matches, skip over to the next chars.
99
+ #
100
+ # Rule API :
101
+ #
102
+ # Each rule must accept parameters:
103
+ # - subject : a string to consider for transformation
104
+ # - position : a symbol indicating where the beginning of the subject string falls, in relationship
105
+ # to the entire word being transformed. Value will be :first, :last, or nil.
106
+ #
107
+ # A rule may return either:
108
+ # - nil : Meaning this rule does not apply.
109
+ # - A array with element 0 containing a replacement string, and element 1 containing an integer describing the
110
+ # number of characters this match consumes in the entire word being transformed.
111
+ # Example : The string 'ew' is changed to 'oo' by the rule 'interior ew becomes oo'. Because this match
112
+ # involves both the 'e' and the 'w', it consumes both characters. The 'w' will not be considered
113
+ # for matching on its own.
114
+ #
115
+ #
116
+ # Outline of rules. Taken from encheferizer.php by Erik Bakker.
117
+ #
118
+ # for first char
119
+ #
120
+ # ^e->i
121
+ # ^o->oo
122
+ #
123
+ # for non-first chars
124
+ #
125
+ # ew->oo
126
+ # e$->e-a
127
+ # f->ff
128
+ # ir->ur, or i->ee if no i has occurred.
129
+ # ow->oo or o->u
130
+ # tion -> shun
131
+ # u->oo
132
+ #
133
+ # An->Un
134
+ # Au->Oo
135
+ # A.->E (A not at the end becomes E)
136
+ # en$->ee
137
+ # e not at the beginning, do nothing. Pointless?
138
+ # th->tt
139
+ # the->zee
140
+ # v->f
141
+ # w->v
142
+ # pass
143
+
144
+ # no recursive cheferizing yet.
145
+ cheferize_rule "pass the bork" do |subject, position|
146
+ [subject, 4] if position == :first && subject[0,4].downcase == 'bork'
147
+ end
148
+
149
+ cheferize_rule "randomly borkify after . or !" do |subject, position|
150
+ if position == :last && (subject[0,1] == '.' || subject[0,1] == '!') && rand(3) == 0
151
+ [', bork bork bork!', 1]
152
+ end
153
+ end
154
+
155
+ # ^e->i
156
+ cheferize_rule "initial e becomes i" do |subject, position|
157
+ if position == :first && subject[0,1].downcase == 'e'
158
+ [ChefString.new('i').in_same_case_as(subject[0,1]), 1]
159
+ end
160
+ end
161
+
162
+ # ^o->oo
163
+ cheferize_rule "initial o becomes oo" do |subject, position|
164
+ if position == :first && subject[0,1].downcase == 'o'
165
+ [ChefString.new('o').in_same_case_as(subject[0,1]) + 'o', 1]
166
+ end
167
+ end
168
+
169
+ # ew->oo, if not at the beginning
170
+ cheferize_rule "interior ew becomes oo" do |subject, position|
171
+ ['oo', 2] if position != :first && subject[0,2] == 'ew'
172
+ end
173
+
174
+ # e$->e-a, if at the end
175
+ cheferize_rule "final e becomes e-a" do |subject, position|
176
+ ['e-a', 1] if position == :last && subject[0,1] == 'e'
177
+ end
178
+
179
+ # f->ff if not at the beginning
180
+ cheferize_rule "interior f becomes ff" do |subject, position|
181
+ ['ff', 1] if position != :first && subject[0,1] == 'f'
182
+ end
183
+
184
+ # ir->ur, or i->ee if no i has occurred.
185
+ cheferize_rule "interior ir becomes ur, or first-occurring interior i becomes ee" do |subject, position|
186
+ if position != :first
187
+ if subject[0,2] == 'ir'
188
+ ['ur', 2]
189
+ elsif subject[0,1] == 'i' && !@chef_saw_an_i
190
+ @chef_saw_an_i = true
191
+ ['ee', 1]
192
+ end
193
+ end
194
+ end
195
+
196
+ # ow->oo or o->u
197
+ cheferize_rule "ow becomes oo, or o becomes u" do |subject, position|
198
+ if position != :first
199
+ if subject[0,2] == 'ow'
200
+ ['oo', 2]
201
+ elsif subject[0,1] == 'o'
202
+ ['u', 1]
203
+ end
204
+ end
205
+ end
206
+
207
+ # tion -> shun
208
+ cheferize_rule "tion becomes shun" do |subject, position|
209
+ if position != :first && subject[0,4] == 'tion'
210
+ ['shun', 4]
211
+ end
212
+ end
213
+
214
+ # u->oo
215
+ cheferize_rule "interior u becomes oo" do |subject, position|
216
+ if position != :first && subject[0,1] == 'u'
217
+ ['oo', 1]
218
+ end
219
+ end
220
+
221
+ # An->Un, an->un
222
+ cheferize_rule "an becomes un" do |subject, position|
223
+ if subject[0,2].downcase == 'an'
224
+ [ChefString.new('u').in_same_case_as(subject[0,1]) + 'n', 2]
225
+ end
226
+ end
227
+
228
+ # Au->Oo, au->oo
229
+ cheferize_rule "au becomes oo" do |subject, position|
230
+ if subject[0,2].downcase == 'au'
231
+ [ChefString.new('o').in_same_case_as(subject[0,1]) + 'o', 2]
232
+ end
233
+ end
234
+
235
+ # A.->E (A not at the end becomes E)
236
+ cheferize_rule "non-final a becomes e" do |subject, position|
237
+ if position != :last && subject[0,1].downcase == 'a'
238
+ [ChefString.new('e').in_same_case_as(subject[0,1]), 1]
239
+ end
240
+ end
241
+
242
+ # en$->ee
243
+ cheferize_rule "final en becomes ee" do |subject, position|
244
+ if position != :first && subject == 'en'
245
+ ['ee', 2]
246
+ end
247
+ end
248
+
249
+ # e not at the beginning, do nothing. Pointless?
250
+
251
+ # the->zee
252
+ cheferize_rule "the becomes zee" do |subject, position|
253
+ if subject[0,3].downcase == 'the'
254
+ [ChefString.new('z').in_same_case_as(subject[0,1]) + 'ee', 3]
255
+ end
256
+ end
257
+
258
+ # th->t
259
+ cheferize_rule "th becomes t" do |subject, position|
260
+ if subject[0,2].downcase == 'th'
261
+ [ChefString.new('t').in_same_case_as(subject[0,1]), 2]
262
+ end
263
+ end
264
+
265
+ # v->f
266
+ cheferize_rule "v becomes f" do |subject, position|
267
+ if subject[0,1].downcase == 'v'
268
+ [ChefString.new('f').in_same_case_as(subject[0,1]), 1]
269
+ end
270
+ end
271
+
272
+ # w->v
273
+ cheferize_rule "w becomes v" do |subject, position|
274
+ if subject[0,1].downcase == 'w'
275
+ [ChefString.new('v').in_same_case_as(subject[0,1]), 1]
276
+ end
277
+ end
278
+
279
+ cheferize_rule "pass on anything else" do |subject, position|
280
+ [subject[0,1], 1]
281
+ end
282
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cheferize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Dean
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - github@mostlyalex.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - cheferize.gemspec
29
+ - lib/cheferize.rb
30
+ - lib/cheferize/chef_string.rb
31
+ - lib/cheferize/version.rb
32
+ homepage: https://github.com/alexdean/cheferize.
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '2.3'
44
+ - - "<="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.7'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.5.2
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Transliterate strings into Swedish Chef.
58
+ test_files: []