well_read_faker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +15 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.adoc +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/lib/books/homer_butler_iliad.txt +13789 -0
- data/lib/well_read_faker.rb +30 -0
- data/lib/well_read_faker/load_bundled_sources.rb +8 -0
- data/lib/well_read_faker/source.rb +49 -0
- data/lib/well_read_faker/version.rb +3 -0
- data/well_read_faker.gemspec +26 -0
- metadata +104 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require "well_read_faker/version"
|
2
|
+
require "well_read_faker/source"
|
3
|
+
|
4
|
+
module WellReadFaker
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def sources
|
9
|
+
@sources ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_source ident, path, options = {}
|
13
|
+
sources[ident] = Source.new(path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_source
|
17
|
+
sources[@default_source_ident]
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_source= ident
|
21
|
+
@default_source_ident = ident
|
22
|
+
end
|
23
|
+
|
24
|
+
def paragraph
|
25
|
+
default_source.paragraph
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
require "well_read_faker/load_bundled_sources"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "mutex_m"
|
2
|
+
|
3
|
+
module WellReadFaker
|
4
|
+
class Source
|
5
|
+
include Mutex_m
|
6
|
+
|
7
|
+
attr_reader :path_to_book, :options
|
8
|
+
|
9
|
+
def initialize path_to_book, options = {}
|
10
|
+
super()
|
11
|
+
@path_to_book = path_to_book
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def text
|
16
|
+
mu_synchronize{ @text ||= load }
|
17
|
+
end
|
18
|
+
|
19
|
+
def paragraph
|
20
|
+
text.sample
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def load
|
26
|
+
raw = File.read path_to_book
|
27
|
+
@text = process_raw_text raw
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_raw_text raw
|
31
|
+
paragraphs = raw.strip.split(/\n\s*\n/)
|
32
|
+
paragraphs.map!{ |m| m.gsub /\s*\n\s*/, " " }
|
33
|
+
while (options.key? :begin) && (paragraphs[0] !~ options[:begin])
|
34
|
+
paragraphs.shift or raise(
|
35
|
+
ArgumentError,
|
36
|
+
"Regular expression #{options[:begin].inspect} not found in text."
|
37
|
+
)
|
38
|
+
end
|
39
|
+
while (options.key? :end) && (paragraphs.pop !~ options[:end])
|
40
|
+
paragraphs.empty? and raise(
|
41
|
+
ArgumentError,
|
42
|
+
"Regular expression #{options[:end].inspect} not found in text."
|
43
|
+
)
|
44
|
+
end
|
45
|
+
paragraphs
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'well_read_faker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "well_read_faker"
|
8
|
+
spec.version = WellReadFaker::VERSION
|
9
|
+
spec.authors = ["Sebastian Skałacki"]
|
10
|
+
spec.email = ["skalee@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Returns random fragments of Iliad or other book.}
|
13
|
+
spec.description = %q{A replacement for various lorem ipsum generators.}
|
14
|
+
spec.homepage = "https://github.com/skalee/well_read_faker"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: well_read_faker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Skałacki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-01 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: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description: A replacement for various lorem ipsum generators.
|
56
|
+
email:
|
57
|
+
- skalee@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".editorconfig"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.adoc
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/rake
|
72
|
+
- bin/rspec
|
73
|
+
- bin/setup
|
74
|
+
- lib/books/homer_butler_iliad.txt
|
75
|
+
- lib/well_read_faker.rb
|
76
|
+
- lib/well_read_faker/load_bundled_sources.rb
|
77
|
+
- lib/well_read_faker/source.rb
|
78
|
+
- lib/well_read_faker/version.rb
|
79
|
+
- well_read_faker.gemspec
|
80
|
+
homepage: https://github.com/skalee/well_read_faker
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.8
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Returns random fragments of Iliad or other book.
|
104
|
+
test_files: []
|