ipsum 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -22
- data/ipsum.gemspec +5 -0
- data/lib/ipsum.rb +3 -77
- data/lib/ipsum/languages.rb +3 -0
- data/lib/ipsum/version.rb +1 -1
- metadata +56 -10
data/Rakefile
CHANGED
@@ -1,24 +1,2 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
desc "Build dictionary"
|
5
|
-
task :dictionary do
|
6
|
-
require 'ipsum'
|
7
|
-
dictionary = {}
|
8
|
-
File.readlines( './dictionaries/latin.txt' ).each do |word|
|
9
|
-
letters = word.split('')
|
10
|
-
sequence = ''
|
11
|
-
letter_index = 0
|
12
|
-
until letters.empty?
|
13
|
-
dictionary[ sequence ] ||= {}
|
14
|
-
dictionary[ sequence ][ letter_index ] ||= {}
|
15
|
-
dictionary[ sequence ][ letter_index ][ letters.first ] ||= 0
|
16
|
-
dictionary[ sequence ][ letter_index ][ letters.first ] += 1
|
17
|
-
sequence += letters.shift
|
18
|
-
sequence = sequence[1..-1] while sequence.size > Ipsum::SEQUENCE_SIZE
|
19
|
-
letter_index += 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
dictionary[ '' ][0].delete( "\n" )
|
23
|
-
p dictionary
|
24
|
-
end
|
data/ipsum.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "ipsum/version"
|
4
|
+
require "ipsum/languages"
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
7
|
s.name = "ipsum"
|
@@ -12,6 +13,10 @@ Gem::Specification.new do |s|
|
|
12
13
|
s.summary = %q{Quickly generate text-like filler ala Lorem Ipsum}
|
13
14
|
s.description = %q{Generate words or sentences for filler text while developing anything which requires text. Most people know this as "Lorem Ipsum". eg: require 'ipsum'; puts 10.sentences}
|
14
15
|
|
16
|
+
Ipsum::LANGUAGES.each do |language|
|
17
|
+
s.add_dependency "ipsum-#{language}", ">= 1.1.0"
|
18
|
+
end
|
19
|
+
|
15
20
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
16
21
|
s.add_development_dependency "rake", ">= 0.8.7"
|
17
22
|
|
data/lib/ipsum.rb
CHANGED
@@ -1,80 +1,6 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
# :main: README.rdoc
|
3
|
-
# :title: Ipsum Documentation
|
4
|
-
|
5
1
|
require 'ipsum/version'
|
2
|
+
require 'ipsum/languages'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
SEQUENCE_SIZE = 3
|
10
|
-
|
11
|
-
@dictionaries = {}
|
12
|
-
|
13
|
-
def self.add_dictionary( language, dictionary )
|
14
|
-
@default_language ||= language
|
15
|
-
@dictionaries[ language.to_sym ] = dictionary
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.default_language
|
19
|
-
@default_language ||= :latin
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.default_language=( language )
|
23
|
-
@default_language = language
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.dictionary( language = self.default_language )
|
27
|
-
begin
|
28
|
-
require "ipsum-#{language}" unless @dictionaries[ language ]
|
29
|
-
rescue LoadError
|
30
|
-
raise "Unable to find language \"#{language}\". Try: gem install ipsum-#{language}"
|
31
|
-
end
|
32
|
-
@dictionaries[ language ]
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.letter_following( sequence, position, language = self.default_language )
|
36
|
-
dict = dictionary( language )
|
37
|
-
sequence_statistics = dictionary( language )[ sequence ][ position ]
|
38
|
-
if sequence_statistics
|
39
|
-
letters = ''
|
40
|
-
sequence_statistics.each_pair do |character,amount|
|
41
|
-
letters << character*amount
|
42
|
-
end
|
43
|
-
letters[rand(letters.size)]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.word( language = self.default_language )
|
48
|
-
letter = nil
|
49
|
-
word = ''
|
50
|
-
until letter == "\n"
|
51
|
-
sequence = ''
|
52
|
-
SEQUENCE_SIZE.times do |enum|
|
53
|
-
sequence << word[-(SEQUENCE_SIZE-enum)] if word[-(SEQUENCE_SIZE-enum)]
|
54
|
-
end
|
55
|
-
letter = letter_following( sequence, word.size, language )
|
56
|
-
word += letter
|
57
|
-
end
|
58
|
-
word.strip
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.sentence( words = rand(5) + 3, language = self.default_language )
|
62
|
-
( [ nil ] * words ).map{|n|self.word( language )}.join(' ').capitalize + '.'
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.sentences( amount = rand(5) + 3, language = self.default_language )
|
66
|
-
( [ nil ] * amount ).map{|n|self.sentence( rand(5) + 3, language )}.join(' ')
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
class Fixnum
|
72
|
-
|
73
|
-
# Generate filler text for this amount of sentences. For example:
|
74
|
-
# 12.sentences
|
75
|
-
# 5.sentences
|
76
|
-
def sentences( language = Ipsum.default_language )
|
77
|
-
Ipsum.sentences( self, language )
|
78
|
-
end
|
79
|
-
|
4
|
+
Ipsum::LANGUAGES.each do |language|
|
5
|
+
require "ipsum-#{language}"
|
80
6
|
end
|
data/lib/ipsum/version.rb
CHANGED
metadata
CHANGED
@@ -3,10 +3,10 @@ name: ipsum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 1
|
7
6
|
- 2
|
8
|
-
-
|
9
|
-
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 2.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Clive Crous
|
@@ -14,12 +14,57 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-03-16 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: ipsum-latin
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
version: 1.1.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ipsum-english
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
version: 1.1.0
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: ipsum-french
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 1
|
60
|
+
- 0
|
61
|
+
version: 1.1.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: bundler
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
23
68
|
none: false
|
24
69
|
requirements:
|
25
70
|
- - ">="
|
@@ -31,10 +76,10 @@ dependencies:
|
|
31
76
|
version: 1.0.0
|
32
77
|
type: :development
|
33
78
|
prerelease: false
|
34
|
-
version_requirements: *
|
79
|
+
version_requirements: *id004
|
35
80
|
- !ruby/object:Gem::Dependency
|
36
81
|
name: rake
|
37
|
-
requirement: &
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
38
83
|
none: false
|
39
84
|
requirements:
|
40
85
|
- - ">="
|
@@ -46,7 +91,7 @@ dependencies:
|
|
46
91
|
version: 0.8.7
|
47
92
|
type: :development
|
48
93
|
prerelease: false
|
49
|
-
version_requirements: *
|
94
|
+
version_requirements: *id005
|
50
95
|
description: "Generate words or sentences for filler text while developing anything which requires text. Most people know this as \"Lorem Ipsum\". eg: require 'ipsum'; puts 10.sentences"
|
51
96
|
email:
|
52
97
|
- clive@crous.co.za
|
@@ -64,6 +109,7 @@ files:
|
|
64
109
|
- dictionaries/latin.txt
|
65
110
|
- ipsum.gemspec
|
66
111
|
- lib/ipsum.rb
|
112
|
+
- lib/ipsum/languages.rb
|
67
113
|
- lib/ipsum/version.rb
|
68
114
|
has_rdoc: true
|
69
115
|
homepage: http://www.darkarts.co.za/ipsum
|
@@ -79,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
125
|
requirements:
|
80
126
|
- - ">="
|
81
127
|
- !ruby/object:Gem::Version
|
82
|
-
hash: -
|
128
|
+
hash: -4449682368167600374
|
83
129
|
segments:
|
84
130
|
- 0
|
85
131
|
version: "0"
|
@@ -88,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
134
|
requirements:
|
89
135
|
- - ">="
|
90
136
|
- !ruby/object:Gem::Version
|
91
|
-
hash: -
|
137
|
+
hash: -4449682368167600374
|
92
138
|
segments:
|
93
139
|
- 0
|
94
140
|
version: "0"
|