personal_faker 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f349662c7c751848d20d89fab7d523aad0987e
4
- data.tar.gz: 3323350b984bd84d3e3df7e2561dbd532c41d3f8
3
+ metadata.gz: 4f5477b9fb514ba53528e19fdef9cfed53b455f0
4
+ data.tar.gz: 8b5cad58a21810d83b3e52fe6b35e831d0c127af
5
5
  SHA512:
6
- metadata.gz: 03b7a46943998487196c35f94273846c955f0a23470cb5654d554c01c3fffe48714734a82401d5ee21207e8eec4e467f83a607823a012b6e705b50f9bba2e836
7
- data.tar.gz: 0c68f05e3b37e81fa18a91df0fb2d0b8dfb9260cc14213dc7b21a6c8a7ad7b9d7d5e2e9e722220762ade405ebc6ad80bbda5096240f7b02fac1fe5f1f9818815
6
+ metadata.gz: 2551088a9444b8e9071ae1ec7a40d83ff9472009891a6546177043106dfa1a645a36343a19ee88ce3a8aaa7dd1f8d6b439c137d9dc7faee41e3e7e23d03f9a54
7
+ data.tar.gz: 7455eb2479f8dbe03540425d8581e705f005e7eb10e0a7145084f244b12e6d11c7b5c42e0f97972864a29050fe24d995dbff8a960410fb73f4da3aee6ea8494d
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # PersonalFaker
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/personal_faker`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem allows you to create fake sentences, questions, etc based on
4
+ a famous text of your choosing.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ On initialization, a table is created that matches each word in the text with the frequencies of words that come after it. The algorithm then loops through one word at a time, picking randomnly a word that comes after it in the text. If no word comes after it (i.e. the end of the text is reached, a random word from the text is chosen).
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,7 +23,17 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ Initialize the faker with your chosen text
27
+
28
+ ```ruby
29
+ my_faker = PersonalFaker::Base.new('macbeth')
30
+ ```
31
+
32
+ Then you can create sentences that are based on the text
33
+
34
+ ```ruby
35
+ title = my_faker.sentence
36
+ ```
26
37
 
27
38
  ## Development
28
39
 
@@ -32,8 +43,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
43
 
33
44
  ## Contributing
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/personal_faker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
-
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sliuu/personal_faker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
37
47
 
38
48
  ## License
39
49
 
@@ -72,5 +72,17 @@ module PersonalFaker
72
72
  end
73
73
  sentence = sentence + "?"
74
74
  end
75
+
76
+ def word
77
+ word = table.keys.sample
78
+ end
79
+
80
+ def text_phrase(count)
81
+ phrase = sentence
82
+ (count - 1).times do
83
+ phrase << " " + sentence
84
+ end
85
+ phrase
86
+ end
75
87
  end
76
88
  end
@@ -1,3 +1,3 @@
1
1
  module PersonalFaker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: personal_faker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephanie Liu
@@ -87,13 +87,13 @@ files:
87
87
  - lib/.DS_Store
88
88
  - lib/personal_faker.rb
89
89
  - lib/personal_faker/.DS_Store
90
- - lib/personal_faker/base.rb
91
90
  - lib/personal_faker/texts/dr-seuss.rtf
92
91
  - lib/personal_faker/texts/macbeth.rtf
93
92
  - lib/personal_faker/texts/pride-and-prejudice.rtf
94
93
  - lib/personal_faker/texts/simple_text.rtf
95
94
  - lib/personal_faker/version.rb
96
95
  - personal_faker-0.0.4.gem
96
+ - personal_faker-0.1.0.gem
97
97
  - personal_faker.gemspec
98
98
  homepage: https://github.com/sliuu/personal_faker
99
99
  licenses:
@@ -1,74 +0,0 @@
1
- module PersonalFaker
2
- class Base
3
- attr_accessor :table
4
- attr_accessor :text
5
- attr_accessor :file
6
-
7
- def initialize(choose_text)
8
- if choose_text == 'dr-seuss'
9
- @file = 'lib/personal_faker/texts/dr-seuss.rtf'
10
- elsif choose_text == 'pride-and-prejudice'
11
- @file = 'lib/personal_faker/texts/pride-and-prejudice.rtf'
12
- elsif choose_text == 'macbeth'
13
- @file = 'lib/personal_faker/texts/macbeth.rtf'
14
- end
15
- end
16
-
17
- def text
18
- return @text unless @text.nil?
19
- @text = File.open(@file, "r").read
20
- @text.gsub!("\n", ' ')
21
- @text.gsub!("\\", '')
22
- @text.gsub!('"', '')
23
- @text.gsub!(' ', ' ')
24
- @text.gsub!(/[_.,!?;:]/, '')
25
- @text.downcase!
26
- @text.gsub!(' i ', ' I ')
27
- end
28
-
29
- def table
30
- return @table unless @table.nil?
31
- position = 0
32
- position_of_second_word = text.index(' ', 1)
33
- table = {}
34
- until position_of_second_word.nil? || text.index(' ', position_of_second_word + 1).nil? do
35
- position_of_second_word += 1
36
- word = text[position..(position_of_second_word - 2)]
37
- second_word = text[position_of_second_word..(text.index(' ', position_of_second_word)-1)]
38
- table[word] ||= []
39
- table[word] << second_word
40
- position = position_of_second_word
41
- position_of_second_word = text.index(' ', position + 1)
42
- end
43
- @table = table
44
- end
45
-
46
- def sentence
47
- word = table.keys.sample.capitalize
48
- sentence = word
49
- 10.times do
50
- if table[word]
51
- word = table[word].sample
52
- else
53
- word = table.keys.sample
54
- end
55
- sentence = sentence + " " + word
56
- end
57
- sentence = sentence + "."
58
- end
59
-
60
- def question
61
- word = table.keys.sample.capitalize
62
- sentence = word
63
- 10.times do
64
- if table[word]
65
- word = table[word].sample
66
- else
67
- word = table.keys.sample
68
- end
69
- sentence = sentence + " " + word
70
- end
71
- sentence = sentence + "?"
72
- end
73
- end
74
- end