Typoglycaemic 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ae1ea8319112439be690a9efe4f6556b41d193bd0a6c0fa7f8a942dacd93e5c
4
+ data.tar.gz: 73c41516431a17f534c55956714084fec8fbaa6bd4ec6f315d4cebd776d9e6ff
5
+ SHA512:
6
+ metadata.gz: ff1d7c4bc783c6d4d2051c892d57f63c1a5c406d2673740b27c7de23cb574f3404c16d16919ab955103e446b5341d756c1c7d08e98ac855483def04688d24a45
7
+ data.tar.gz: d114dff6d3fcbaa8f1ffea0257822c6c1b6f89431a1c013b1a1d699e6b2f6b667cac538211449a975cca82f46d4c76e48e63f3a4a04a8c35eecc6fa93d618223
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ /bin/
14
+ /vendor/
15
+ /vendor.noindex/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.1] - 14th of July 2019
10
+
11
+ - Error in gemspec, fixed.
12
+
13
+ ## [0.1.0] - 14th of July 2019
14
+
15
+ - The `Typoglycaemic(str)` method now returns the object instead of the jumbled string.
16
+ - Inside the object all the strings are frozen, no pesky mutations.
17
+ - The `Typoglycaemic(str)` method (and the initializer) will also accept a Typoglycaemic object and preserve the original and jumbled text.
18
+
19
+ ## [0.0.1] - 10th of July 2019
20
+
21
+ ### Added
22
+
23
+ - First working version.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "minitest"
6
+ gem 'pry-byebug'
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Iain Barnett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # Typoglycaemic
2
+
3
+ ## Usage
4
+
5
+ ```ruby
6
+ require 'typoglycaemic'
7
+ ```
8
+
9
+
10
+ ```ruby
11
+ words = <<~STR
12
+ According to a researcher at Cambridge University, it doesn't matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole.
13
+ STR
14
+
15
+ puts Typoglycaemic(words).jumbled
16
+ ```
17
+
18
+ The output:
19
+
20
+ > Accorindg to a reeascrehr at Cmbairdge Uivnesrtiy, it deso'nt matter in what order the letters in a word are, the only ipmortnat tinhg is that the fisrt and last letter be at the rgiht pacle. The rset can be a toatl mses and you can still raed it wtiouht poblerm. Tihs is bceasue the huamn mnid does not read eevry letter by iteslf but the wrod as a wolhe.
21
+
22
+ ```ruby
23
+ str = "A doctor has admitted the manslaughter of a teenage cancer patient who died after a hospital drug blunder."
24
+ puts Typoglycaemic(str).jumbled
25
+ ```
26
+
27
+ The output:
28
+
29
+ > A docotr has amditted the mnsalugather of a teengae cnaecr ptiaent who died after a hspotail drug blnduer.
30
+
31
+
32
+ ```ruby
33
+ str = "In the Victorian era, a lovely emerald green, partially formulated from arsenic, was used in fabrics and popular floral headdresses."
34
+ puts Typoglycaemic(str).jumbled
35
+ ```
36
+
37
+ The output:
38
+
39
+ > In the Vitorcain era, a lovley emreald green, patirally fromlauetd form asenric, was uesd in fbarics and poplaur folarl headdersses.
40
+
41
+ The original is around if needed:
42
+
43
+ ```ruby
44
+ tc = Typoglycaemic(str)
45
+ tc.original
46
+ ```
47
+
48
+
49
+ ## The rules
50
+
51
+ It follows the rules set out [in this article](https://www.dictionary.com/e/typoglycemia/).
52
+
53
+
54
+ ## Why this library?
55
+
56
+ Mainly because I was getting bored of debugging and wanted to do something else, but also because I read this:
57
+
58
+ > In a final study, Gervais and Norenzayan used an even more subtle way of activating analytic thinking: by having participants fill out a survey measuring their religious beliefs that was printed in either clear font or font that was difficult to read. Prior research has shown that difficult-to-read font promotes analytic thinking by forcing participants to slow down and think more carefully about the meaning of what they are reading. The researchers found that participants who filled out a survey that was printed in unclear font expressed less belief as compared to those who filled out the same survey in the clear font.
59
+
60
+ [How Critical Thinkers Lose Their Faith in God, Daisy Grewal, May 1, 2012, Scientific American](https://www.scientificamerican.com/article/how-critical-thinkers-lose-faith-god/)
61
+
62
+ I might try using it on social networks when I want my "opponent" in a debate to bypass "System 1".
63
+
64
+ ## Installation
65
+
66
+ Add this line to your application's Gemfile:
67
+
68
+ ```ruby
69
+ gem 'typoglycaemic'
70
+ ```
71
+
72
+ And then execute:
73
+
74
+ $ bundle
75
+
76
+ Or install it yourself as:
77
+
78
+ $ gem install typoglycaemic
79
+
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yb66/typoglycaemic.
@@ -0,0 +1,118 @@
1
+ # Jumble words in a typoglycaemic fashion.
2
+ class Typoglycaemic
3
+ class Error < StandardError; end
4
+
5
+ # Ignore these functional words.
6
+ BESIDES = %w{a and at be by it on the to}
7
+
8
+ # The chance of a pair of letters being jumbled is 50/50.
9
+ DEFAULT_CHANCE = 50
10
+
11
+
12
+ # @example
13
+ # str = "In the Victorian era, a lovely emerald green, partially formulated from arsenic, was used in fabrics and popular floral headdresses."
14
+ # puts Typoglycaemic(str)
15
+ # > In the Vitorcain era, a lovley emreald green, patirally fromlauetd form asenric, was uesd in fbarics and poplaur folarl headdersses.
16
+ #
17
+ # @param [String] original
18
+ def initialize original
19
+ if original.respond_to?(:typoglycaemized)
20
+ @original = original.original
21
+ @typoglycaemized = original.typoglycaemized
22
+ else
23
+ @original = original
24
+ @chance = DEFAULT_CHANCE
25
+ @typoglycaemized = self.class.typoglycaemize @original, @chance
26
+ end
27
+ @original.freeze and @typoglycaemized.freeze and @frozen = true
28
+ end
29
+
30
+ # @return [String]
31
+ attr_reader :typoglycaemized, :original, :frozen
32
+
33
+ # because that's a mouthful
34
+ alias_method :jumbled, :typoglycaemized
35
+
36
+
37
+ class << self
38
+
39
+ # @param [String] original
40
+ # @param [Integer] chance
41
+ def typoglycaemize original, chance
42
+ if original =~ /\s/
43
+ original.split(/\s/).map{|word|
44
+ if word.size <= 3 or BESIDES.include?(word.downcase)
45
+ word
46
+ else
47
+ to_typo( word, chance)
48
+ end
49
+ }.join(" ")
50
+ else
51
+ to_typo original, chance
52
+ end
53
+ end
54
+
55
+
56
+ # Regex to partition by.
57
+ PATTERN = /
58
+ (?:
59
+ (?<=\b)\s # end of a word
60
+ )
61
+ |
62
+ (?:
63
+ [[:punct:]](?=\s) # punctuation at the end of a word
64
+ )
65
+ |
66
+ (?:
67
+ ([a-z])\1 # repeated letters
68
+ )
69
+ /x
70
+
71
+ # @api private
72
+ # @see #typoglycaemize
73
+ def to_typo original, chance
74
+ h,*middle,t = original.split //
75
+ newstring = h
76
+ t ||= ""
77
+ t = middle.delete_at(-1) + t if /[[:punct:]]/ =~ t
78
+
79
+ middle = middle.join
80
+ middle.size >= 7 ? chance -= 10 : chance += 10
81
+
82
+ until middle.empty?
83
+ head,wall,tail = middle.partition PATTERN
84
+ head = head.split //
85
+ # use an external iterator as the array is being mutated.
86
+ for i in 0..head.size-1 do
87
+ if b = head[i+1] # control the jumbling
88
+ # as it gets more jumbled the chance of being jumbled
89
+ # goes down
90
+ if rand(0..99) < chance
91
+ a = head[i]
92
+ head[i] = b
93
+ head[i+1] = a
94
+ chance -= 10 unless chance <= 10
95
+ else
96
+ # and goes up if less jumbled
97
+ chance += 10 unless chance >= 90
98
+ end
99
+ end
100
+ end
101
+ newstring << head.join
102
+ newstring << wall
103
+ middle = tail
104
+ end
105
+ newstring << t
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+
112
+
113
+ # For convenience.
114
+ # @param [Typoglycaemic,String] original
115
+ # @return [Typoglycaemic]
116
+ def Typoglycaemic(original)
117
+ Typoglycaemic.new(original)
118
+ end
@@ -0,0 +1,4 @@
1
+ class Typoglycaemic
2
+ #@see https://semver.org/spec/v2.0.0.html
3
+ VERSION = "0.1.1"
4
+ end
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "typoglycaemic/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Typoglycaemic"
8
+ spec.version = Typoglycaemic::VERSION
9
+ spec.authors = ["iain barnett"]
10
+ spec.email = ["helpful-iain@theprintedbird.com"]
11
+ spec.summary = %q{An implementation of typoglycaemic word jumbling. Yu'oll hvae no difficltuy raeidng tihs, rgiht?}
12
+ spec.description = %q{Accorindg to a reeascrehr at Cmbairdge Uivnesrtiy, it deso'nt matter in what order the letters in a word are, the only ipmortnat tinhg is that the fisrt and last letter be at the rgiht pacle. The rset can be a toatl mses and you can still raed it wtiouht poblerm. Tihs is bceasue the huamn mnid does not read eevry letter by iteslf but the wrod as a wolhe.}
13
+ spec.homepage = "https://github.com/yb66/typoglycaemic"
14
+
15
+ if spec.respond_to?(:metadata)
16
+ spec.metadata = {
17
+ "homepage_uri" => spec.homepage,
18
+ "source_code_uri" => "https://github.com/yb66/typoglycaemic",
19
+ "changelog_uri" => "https://github.com/yb66/typoglycaemic/blob/master/CHANGELOG.md",
20
+ }
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 2.0"
36
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Typoglycaemic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - iain barnett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Accorindg to a reeascrehr at Cmbairdge Uivnesrtiy, it deso'nt matter
28
+ in what order the letters in a word are, the only ipmortnat tinhg is that the fisrt
29
+ and last letter be at the rgiht pacle. The rset can be a toatl mses and you can
30
+ still raed it wtiouht poblerm. Tihs is bceasue the huamn mnid does not read eevry
31
+ letter by iteslf but the wrod as a wolhe.
32
+ email:
33
+ - helpful-iain@theprintedbird.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - ".gitignore"
39
+ - ".travis.yml"
40
+ - CHANGELOG.md
41
+ - Gemfile
42
+ - LICENCE.txt
43
+ - README.md
44
+ - lib/typoglycaemic.rb
45
+ - lib/typoglycaemic/version.rb
46
+ - typoglycaemic.gemspec
47
+ homepage: https://github.com/yb66/typoglycaemic
48
+ licenses: []
49
+ metadata:
50
+ homepage_uri: https://github.com/yb66/typoglycaemic
51
+ source_code_uri: https://github.com/yb66/typoglycaemic
52
+ changelog_uri: https://github.com/yb66/typoglycaemic/blob/master/CHANGELOG.md
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.7.6
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: An implementation of typoglycaemic word jumbling. Yu'oll hvae no difficltuy
73
+ raeidng tihs, rgiht?
74
+ test_files: []