oulipo 0.1.1 → 0.1.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/README.md CHANGED
@@ -8,6 +8,8 @@ It's still young, and very much liable to change.
8
8
 
9
9
  The real [Oulipo](http://en.wikipedia.org/wiki/Oulipo) is a gathering of writers and mathmeticians who seek to create works using constrained writing techniques.
10
10
 
11
+ Install with `gem install oulipo`.
12
+
11
13
  ## Lipograms and Pangrams
12
14
 
13
15
  Oulipo can detect lipograms and pangrams.
@@ -16,61 +18,89 @@ A lipogram willfully shuns one or more letters of the alphabet.
16
18
 
17
19
  In the following snippet of a poem, every letter of the alphabet except 'e' is used:
18
20
 
19
- stanza = <<-GYLES_BRANDRETH
20
-
21
- Not work of man, nor sport of child
22
- Finds Nassan on this mazy wild;
23
- Lax grow his joints, limbs toil in vain--
24
- Poor wight! why didst thou quit that plain?
25
-
26
- GYLES_BRANDRETH
27
-
28
- Oulipo.lipogram?(stanza) # => true
29
- Oulipo.absent_letters(stanza) # => ['e']
21
+ ```ruby
22
+ stanza = <<-GYLES_BRANDRETH
23
+
24
+ Not work of man, nor sport of child
25
+ Finds Nassan on this mazy wild;
26
+ Lax grow his joints, limbs toil in vain--
27
+ Poor wight! why didst thou quit that plain?
28
+
29
+ GYLES_BRANDRETH
30
+
31
+ Oulipo.lipogram?(stanza) # => true
32
+ Oulipo.absent_letters(stanza) # => ['e']
33
+ ```
30
34
 
31
35
  In contrast, a pangram uses all the letters of the alphabet (often seen jumping lazy dogs):
32
36
 
33
- sentence = 'Big fjords vex quick waltz nymph.'
34
-
35
- Oulipo.pangram?(sentence) # => true
37
+ ```ruby
38
+ sentence = 'Big fjords vex quick waltz nymph.'
39
+
40
+ Oulipo.pangram?(sentence) # => true
41
+ ```
36
42
 
37
43
  ## Univocalims
38
44
 
39
45
  A univocalism is a poem written using only one type of vowel.
40
46
 
41
- poem = <<-POEM
42
- No cool monsoons blow soft on Oxford dons,
43
- Orthodox, jog-trot, book-worm Solomons
44
- POEM
47
+ ```ruby
48
+ poem = <<-POEM
45
49
 
46
- Oulipo.univocalism?(poem) # => true
50
+ No cool monsoons blow soft on Oxford dons,
51
+ Orthodox, jog-trot, book-worm Solomons
52
+
53
+ POEM
54
+
55
+ Oulipo.univocalism?(poem) # => true
56
+ ```
47
57
 
48
58
  ## Palindromes
49
59
 
50
60
  Palindromes read the same way, backwards or forwards:
51
61
 
52
- Oulipo.palindrome?('Eva, can I stab bats in a cave?') # => true
62
+ ```ruby
63
+ Oulipo.palindrome?('Eva, can I stab bats in a cave?') # => true
64
+ ```
53
65
 
54
66
  ## Chaterisms
55
67
 
56
- Oulipo knows about Chaterisms.
57
-
58
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.
59
69
 
60
- Oulipo.chaterism? 'Ruby loves poetry!' # => true
61
- Oulipo.chaterism? 'Poetry loves Ruby, too.' # => true
62
-
63
- poem = <<-WORDS
64
-
65
- One
66
- poem
67
- grows,
68
- author
69
- watches,
70
- helpless --
71
- syllables
72
- accumulate.
73
-
74
- WORDS
75
-
76
- Oulipo.snowball? poem # => true
70
+ ```ruby
71
+ Oulipo.chaterism? 'Ruby loves poetry!' # => true
72
+ Oulipo.chaterism? 'Poetry loves Ruby, too.' # => true
73
+
74
+ poem = <<-WORDS
75
+
76
+ One
77
+ poem
78
+ grows,
79
+ author
80
+ watches,
81
+ helpless --
82
+ syllables
83
+ accumulate.
84
+
85
+ WORDS
86
+
87
+ Oulipo.snowball? poem # => true
88
+ ```
89
+
90
+ ## Alliteration
91
+
92
+ Oulipo can tell you about alliterations.
93
+
94
+ ```ruby
95
+ Oulipo.alliteration? 'ravenous Ruby relishes radical raconteurs' # => true
96
+ ```
97
+
98
+ Normal alliteration's a little harsh, so you can give it a threshold, too.
99
+
100
+ ```ruby
101
+ phrase = 'quick queens quibble over quails'
102
+
103
+ Oulipo.allitertivity(phrase) # => 0.8 (4/5 words start with 'q')
104
+ Oulipo.alleration?(phrase, :threshold => 0.7) # => true
105
+ Oulipo.alleration?(phrase, :threshold => 0.9) # => false
106
+ ```
data/lib/oulipo.rb CHANGED
@@ -46,4 +46,24 @@ class Oulipo
46
46
  sequence = phrase.downcase.gsub(/[^a-z]/, '')
47
47
  sequence.reverse == sequence
48
48
  end
49
+
50
+ def self.alliteration?(phrase, options = {})
51
+ threshold = options.delete(:threshold) || 1
52
+ self.alliterativity(phrase) >= threshold
53
+ end
54
+
55
+ # Calculate an alliteration score
56
+ def self.alliterativity(phrase)
57
+ words = phrase.downcase.gsub(/[^a-z\s]/, '').split
58
+ leading_letters = words.map(&:chr)
59
+
60
+ leading_letter_counts = leading_letters.inject({}) do |result, letter|
61
+ result[letter] ||= 0
62
+ result[letter] += 1
63
+ result
64
+ end
65
+
66
+ most_used_count = leading_letter_counts.max_by { |kv| kv.last }.pop
67
+ most_used_count.to_f / words.length
68
+ end
49
69
  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.1.1"
6
+ s.version = "0.1.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"
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "alliteration" do
4
+
5
+ let(:performer) { Oulipo }
6
+
7
+ let(:pure_alliteration) { 'spec step succeeds speedily' }
8
+ let(:mostly_alliterative) { 'quick queens quibble over quails' }
9
+
10
+ it "detects pure alliteration" do
11
+ performer.alliteration?(pure_alliteration).should == true
12
+ end
13
+
14
+ it "tells us the alliterativity of a phrase" do
15
+ performer.alliterativity(pure_alliteration).should == 1.0
16
+ performer.alliterativity(mostly_alliterative).should == 0.8
17
+ end
18
+
19
+ it "detects alliteration with a threshold" do
20
+ performer.alliteration?(mostly_alliterative).should == false
21
+ performer.alliteration?(mostly_alliterative, :threshold => 0.7).should == true
22
+ performer.alliteration?(mostly_alliterative, :threshold => 0.8).should == true
23
+ performer.alliteration?(mostly_alliterative, :threshold => 0.9).should == false
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oulipo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pete Nicholls
@@ -30,6 +30,7 @@ files:
30
30
  - Rakefile
31
31
  - lib/oulipo.rb
32
32
  - oulipo.gemspec
33
+ - spec/alliteration_spec.rb
33
34
  - spec/chaterisms_spec.rb
34
35
  - spec/lipograms_spec.rb
35
36
  - spec/palindromes_spec.rb
@@ -64,6 +65,7 @@ signing_key:
64
65
  specification_version: 3
65
66
  summary: Constrained writing with Ruby.
66
67
  test_files:
68
+ - spec/alliteration_spec.rb
67
69
  - spec/chaterisms_spec.rb
68
70
  - spec/lipograms_spec.rb
69
71
  - spec/palindromes_spec.rb