oulipo 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oulipo (0.3.0)
4
+ oulipo (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -14,7 +14,7 @@ Install with `gem install oulipo` and `require 'oulipo'` as needed.
14
14
 
15
15
  Oulipo can detect lipograms and pangrams.
16
16
 
17
- A lipogram willfully shuns one or more letters of the alphabet.
17
+ A **lipogram** willfully shuns one or more letters of the alphabet.
18
18
 
19
19
  In the following snippet of a poem, every letter of the alphabet except 'e' is used:
20
20
 
@@ -32,7 +32,7 @@ Oulipo.lipogram?(stanza) # => true
32
32
  Oulipo.absent_letters(stanza) # => ['e']
33
33
  ```
34
34
 
35
- In contrast, a pangram uses all the letters of the alphabet (often seen jumping lazy dogs):
35
+ In contrast, a **pangram** uses all the letters of the alphabet (often seen jumping lazy dogs):
36
36
 
37
37
  ```ruby
38
38
  sentence = 'Big fjords vex quick waltz nymph.'
@@ -40,9 +40,17 @@ sentence = 'Big fjords vex quick waltz nymph.'
40
40
  Oulipo.pangram?(sentence) # => true
41
41
  ```
42
42
 
43
+ The **prisoner's constraint**, also known as the **Macao constraint**, is a type of lipogram in which no letters can be ascenders (b, d, f, g, h, j, k, l) or descenders (p, q, t, y).
44
+
45
+ ```ruby
46
+ line = "rain's music runs in rivers"
47
+
48
+ Oulipo.prisoner?(line) # => true
49
+ ```
50
+
43
51
  ## Univocalims
44
52
 
45
- A univocalism is a poem written using only one type of vowel.
53
+ A **univocalism** is a poem written using only one type of vowel.
46
54
 
47
55
  ```ruby
48
56
  poem = <<-POEM
@@ -57,7 +65,7 @@ Oulipo.univocalism?(poem) # => true
57
65
 
58
66
  ## Palindromes
59
67
 
60
- Palindromes read the same way, backwards or forwards:
68
+ **Palindromes** read the same way, backwards or forwards:
61
69
 
62
70
  ```ruby
63
71
  Oulipo.palindrome?('Eva, can I stab bats in a cave?') # => true
@@ -65,7 +73,7 @@ Oulipo.palindrome?('Eva, can I stab bats in a cave?') # => true
65
73
 
66
74
  ## Chaterisms
67
75
 
68
- A chaterism is a poem where either each successive word in the poem grows by one letter (also known as "snowball poem") or shrinks by one letter.
76
+ A **chaterism** is a poem where either each successive word in the poem grows by one letter (also known as "snowball poem") or shrinks by one letter.
69
77
 
70
78
  ```ruby
71
79
  Oulipo.chaterism? 'Ruby loves poetry!' # => true
@@ -107,7 +115,7 @@ Oulipo.alliteration?(phrase, :threshold => 0.9) # => false
107
115
 
108
116
  ## N+7
109
117
 
110
- In N+7 (sometimes known as S+7), each noun in a text is replaced with the noun seven entries after it in a dictionary.
118
+ In **N+7** (sometimes known as **S+7**), each noun in a text is replaced with the noun seven entries after it in a dictionary.
111
119
 
112
120
  ```ruby
113
121
  dictionary = Oulipo::WordList.load('big_list_of_nouns.txt')
@@ -134,7 +142,7 @@ king_john = 'To gild refined gold, to paint the lily'
134
142
  Oulipo.n_plus(1, king_john, dictionary) # => 'To mine refined ore, to cast the iron'
135
143
  ```
136
144
 
137
- ## Extending String
145
+ ## String Extensions
138
146
 
139
147
  You can optionally extend `String`, if you need to.
140
148
 
data/lib/oulipo.rb CHANGED
@@ -8,7 +8,7 @@ module Oulipo
8
8
 
9
9
  [:absent_letters, :pangram?, :lipogram?, :chaterism?,
10
10
  :univocalism?, :snowball?, :palindrome?, :alliteration?,
11
- :alliterativity].each do |method|
11
+ :alliterativity, :present_letters, :prisoner?].each do |method|
12
12
  define_singleton_method(method.to_sym) do |*args|
13
13
  EnhancedString.new(args.shift).send(method.to_sym, *args)
14
14
  end
@@ -2,6 +2,7 @@ module Oulipo
2
2
  module StringExtensions
3
3
  ALPHABET = 'a'..'z'
4
4
  VOWELS = %w{ a e i o u }
5
+ ASCENDERS_AND_DESCENDERS = %w{ b d f g h j k l p q t y }
5
6
 
6
7
  # Whether the string uses alliteration or not.
7
8
  # Accepts a :threshold option for determining whether the string
@@ -48,7 +49,6 @@ module Oulipo
48
49
 
49
50
  # Returns true if only one vowel is used
50
51
  def univocalism?
51
- present_letters = self.downcase.split('').uniq
52
52
  (VOWELS - present_letters).length == 4
53
53
  end
54
54
 
@@ -67,9 +67,12 @@ module Oulipo
67
67
 
68
68
  # Returns an array of letters that are absent
69
69
  def absent_letters
70
- present_letters = self.downcase.split('').uniq
71
- missing_letters = ALPHABET.to_a - present_letters
72
- missing_letters.empty? ? nil : missing_letters
70
+ remaining = ALPHABET.to_a - present_letters
71
+ remaining.empty? ? nil : remaining
72
+ end
73
+
74
+ def present_letters
75
+ self.downcase.gsub(/[^a-z]/, '').split('').uniq.sort
73
76
  end
74
77
 
75
78
  # Returns true if all letters of the alphabet are used
@@ -82,5 +85,10 @@ module Oulipo
82
85
  !self.pangram?
83
86
  end
84
87
 
88
+ # Returns true if no letters are ascenders (b, d, f, g, h, j, k, l) or descenders (p, q, t, y)
89
+ def prisoner?
90
+ (ASCENDERS_AND_DESCENDERS & present_letters).empty?
91
+ end
92
+
85
93
  end
86
94
  end
data/oulipo.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "oulipo"
6
- s.version = "0.3.1"
6
+ s.version = "0.3.2"
7
7
  s.date = Time.now.strftime('%Y-%m-%d')
8
8
  s.homepage = "http://github.com/Aupajo/oulipo"
9
9
  s.email = "pete@metanation.com"
@@ -5,12 +5,19 @@ describe "lipograms and pangrams" do
5
5
 
6
6
  let(:pangram) { 'The quick brown fox jumps over a lazy god' }
7
7
  let(:lipogram) { 'The quick grey fox jumps over lazy gods' }
8
+ let(:prisoner) { "rain's music runs in rivers" }
9
+ let(:bradley_manning) { 'bradley e. manning' }
8
10
 
9
11
  it "shows absent letters" do
10
12
  pangram.absent_letters.should be_nil
11
13
  lipogram.absent_letters.should == %w{ b n w }
12
14
  end
13
15
 
16
+ it "shows present letters" do
17
+ pangram.present_letters.should == ('a'..'z').to_a
18
+ lipogram.present_letters.should == ('a'..'z').to_a - %w{ b n w }
19
+ end
20
+
14
21
  it "can tell a pangram from a lipogram" do
15
22
  lipogram.should be_lipogram
16
23
  pangram.should_not be_lipogram
@@ -19,8 +26,16 @@ describe "lipograms and pangrams" do
19
26
  pangram.should be_pangram
20
27
  end
21
28
 
29
+ it "can tell a prisoner's constraint" do
30
+ prisoner.should be_prisoner
31
+ lipogram.should_not be_prisoner
32
+ pangram.should_not be_prisoner
33
+ bradley_manning.should_not be_prisoner
34
+ end
35
+
22
36
  it "is accessible via Oulipo" do
23
- Oulipo.should forward_to_enhanced_string(:lipogram?, :pangram?)
37
+ Oulipo.should forward_to_enhanced_string(:absent_letters, :present_letters,
38
+ :lipogram?, :pangram?, :prisoner?)
24
39
  end
25
40
 
26
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oulipo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: