programming_ipsum 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b2900789771e52eafd60ee8715078e261bf5d8d
4
+ data.tar.gz: dc01f8d73ab7269c69ff6c73f89f9250d316f046
5
+ SHA512:
6
+ metadata.gz: 61a715c37e3715ba86125053eccf908bec7c4e992898a9c99aaeb3bb72d1ffe69e2341eb6c366bccdb0e6d2e7f62dec241e94d6ea9366aeef99760b2f732f121
7
+ data.tar.gz: 884ede4aa70c92a4ed9811933324583fdbc11228d84a52967d0a10c2da63fec9923ca8a4dcc14e034fa8687830b43affd4953f073e3362b2ac9b0041ca9e6052
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
4
+ --tag ~skip
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in programming_ipsum.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Brian Bugh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # ProgrammingIpsum
2
+
3
+ Generate fantastic programming advice using a gem. Useful if you want to increase your score on Stack Overflow, make money as a technical consultant, or sound smart in a job interview.
4
+
5
+ ## Example
6
+
7
+ If someone asks you a question about why their code doesn't work, you could respond with:
8
+
9
+ > You haven't iterated a parameter, so your element is just initializing forever. Check the documentation on processes, and see if there's not a dependency or list you can use to have the instance initialize it automatically. Your loops didn't have return types for the references of the index's length.
10
+
11
+ Perhaps someone's boolean dependencies aren't looping and they want to know why:
12
+
13
+ > Since you're using Rails, return types are overkill here. If you switch to JavaScript, you won't keep seeing these out of scope return types. You could initialize it as a string, but you'd need to return an instance also or your results will be wrong. If it's not exiting your closures, something is very wrong... It loops each reference and exits a boolean dependency, and then the dependency is handed to the next dependency.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'programming_ipsum'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install programming_ipsum
30
+
31
+ ## Usage
32
+
33
+ To generate some helpful advice in your application, use `sequence` like so:
34
+
35
+ ```ruby
36
+ advice = ProgrammingIpsum::AdviceIpsum.new
37
+ output = advice.sequence(5)
38
+ ```
39
+
40
+ To view all possible generated phrases (intended for debugging or satisfying curious cats):
41
+
42
+ ```ruby
43
+ advice = ProgrammingIpsum::AdviceIpsum.new
44
+ output = advice.all_phrases
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment with bad advice to your heart's content.
50
+
51
+ To install the development version of this gem onto your local machine, run `bundle exec rake install`. At this point you may begin celebrating your success by cheering, dancing, or some other creative expression.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports, pull requests, and compliments are welcome on GitHub at https://github.com/bbugh/programming_ipsum.
56
+
57
+ Expanded phrases and contexts can be suggested as well, see `lib/programming_ipsum/advice_ipsum.rb` for the format and create a pull request. If I like them, I'll accept them.
58
+
59
+ If you're new to open source contribution, [this Beginner's Guide to Contributing to Open Source Projects](https://blog.newrelic.com/2014/05/05/open-source_gettingstarted/) is a great resource.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). That means you can use it however you want to, but you have to give me credit. That's just polite.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "programming_ipsum"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,149 @@
1
+ require_relative 'base'
2
+
3
+ module ProgrammingIpsum
4
+ class AdviceIpsum < Base
5
+ def initialize
6
+ super(PHRASES, CONTEXT)
7
+ end
8
+
9
+ PHRASES = [
10
+ "Your <%= plural_noun %> didn't have <%= plural_noun %> for the <%= plural_noun %> of the <%= possessive_noun %> <%= attribute %>.",
11
+ "<%= article(adjective).capitalize %> <%= type %> was <%= past_verb %>, but then you passed in the <%= noun %> for the <%= type %> <%= noun %> and it couldn't <%= verb %>.",
12
+ "Your code <%= past_verb %> the array's <%= plural_noun %> with <%= article noun %> but didn't <%= verb %> the <%= noun %>.",
13
+ "When you <%= past_verb %> the <%= noun %>, the <%= possessive_noun %> <%= noun %> was a <%= type %>, but you should have <%= past_verb %> the <%= noun %> instead.",
14
+ "Wouldn't <%= verbing %> <%= article noun %> on the <%= noun %> be better?",
15
+ "You can do this by <%= verbing %> an <%= adjective %> <%= type %> to your <%= noun %>, but you'll also need to <%= verb %> the <%= noun %> if you haven't yet.",
16
+ "It sounds like maybe the <%= noun %> was <%= past_verb %> somehow between the <%= verb %> and the <%= verb %>.",
17
+ "You haven't <%= past_verb %> <%= article noun %>, so your <%= noun %> is just <%= verbing %> forever.",
18
+ "Since you are just <%= verbing %> <%= article noun %>, you shouldn't have to <%= verb %> your <%= noun %>.",
19
+ "It works for me, did you <%= verb %> your <%= noun %>?",
20
+ "I recommend <%= verbing %> and <%= verbing %> the <%= noun %>, then working backwards from there.",
21
+ "Also make sure you are <%= verbing %> the <%= plural_noun %> with the same <%= noun %>.",
22
+ "The <%= plural_noun %> are redundant, replace them with <%= article noun %>.",
23
+ "It's a bad idea to <%= verb %> <%= plural_noun %>, <%= plural_noun %>, and <%= plural_noun %> at the same time.",
24
+ "I can't comment on the <%= plural_noun %>, but <%= plural_noun %> are hard to use; that's why we have <%= plural_noun %> and <%= plural_noun %>.",
25
+ "Try \"<%= noun %> katas\" where you repeat exercises in <%= plural_noun %> until it's is second nature.",
26
+ "It's annoying but you need to <%= verb %> all of the <%= adjective %> <%= plural_noun %> first.",
27
+ "You may want to use <%= plural_noun %> that support <%= verbing %>.",
28
+ "For <%= adjective %> <%= plural_noun %>, using the <%= adjective %> <%= noun %> may be \"traditional\" but most people use <%= article adjective %> <%= noun %>, even when <%= verbing %> <%= plural_noun %>.",
29
+ "If you can't <%= verb %> the <%= noun %>, you can just use the <%= noun %> to make it faster.",
30
+ "Using <%= article noun %> instead of <%= article noun %> allows for <%= verbing %> additional <%= plural_noun %>.",
31
+ "If it's not <%= verbing %> your <%= plural_noun %>, something is very wrong...",
32
+ "You could <%= verb %> it as <%= article type %>, but you'd need to <%= verb %> <%= article noun %> also or your results will be wrong.",
33
+ "If you haven't seen <%= article adjective %> <%= noun %> before, it's not as magical as it might appear.",
34
+ "It <%= verbs %> each <%= noun %> and <%= verbs %> <%= article type %> <%= noun %>, and then the <%= noun %> is handed to the next <%= noun %>.",
35
+ "In this case, your <%= noun %> is simply <%= article type %> that <%= verbs %> the <%= noun %>.",
36
+ "<%= article(noun).capitalize %> is just <%= article type %>; when <%= past_verb %>, it <%= verbs %> the <%= noun %> <%= past_verb %> for each <%= noun %> in the <%= plural_noun %> (in this case, the <%= noun %>).",
37
+ "Since you're using <%= language %>, <%= plural_noun %> are overkill here.",
38
+ "This <%= verbs %> <%= adjective %> <%= plural_noun %> because <%= language %> doesn't support <%= plural_noun %>.",
39
+ "Trying to <%= verb %> <%= article noun %> is not purely functional, and will have side effects.",
40
+ "It's more reliable to use <%= article noun %> instead of <%= article noun %> to <%= verb %> the <%= noun %> and the <%= noun %>, but you have to make sure to <%= verb %> the <%= noun %> or you'll get this error.",
41
+ "I'd <%= verb %> <%= article noun %>. That way, your <%= plural_noun %> will <%= past_verb %> the <%= possessive_noun %> <%= noun %>.",
42
+ "You could switch to <%= language %>, it's a lot better at <%= verbing %> <%= plural_noun %>.",
43
+ "To start <%= verbing %>, use <%= article noun %> and it will <%= verb %> it for you automatically.",
44
+ "I recommend that you start with <%= verbing %> the <%= adjective %> <%= plural_noun %> first, because you already have everything you need to <%= verb %> <%= article noun %>.",
45
+ "You could just use <%= article adjective %> <%= noun %> API, they're more reliable.",
46
+ "<%= plural_noun.capitalize %> don't have <%= adjective %> <%= plural_noun %>, but <%= plural_noun %> shouldn't fail to <%= verb %> the <%= attribute %> property.",
47
+ "If you switch to <%= language %>, you won't keep seeing these <%= adjective %> <%= plural_noun %>. :)",
48
+ "It's telling you that the <%= noun %> is <%= adjective %>. Judging from your code, I think it's because you just <%= past_verb %> the <%= attribute %> as plain text, but you didn't <%= verb %> the content as <%= article type %>.",
49
+ "You could <%= verb %> the <%= noun %> <%= attribute %> in the <%= noun %>, but that's really a bad idea. I would probably <%= verb %> <%= article noun %> instead.",
50
+ "There's a bug in <%= language %> that <%= verbs %> the <%= noun %> when you try to do that. As a workaround, use some <%= plural_noun %> to <%= verb %> <%= article noun %>, and it will avoid those pesky <%= adjective %> <%= plural_noun %>.",
51
+ "It's not the prettiest solution, but you can <%= verb %> until it <%= verbs %> <%= article noun %>.",
52
+ "I'm a core contributor to <%= language %>, so I know what I'm talking about.",
53
+ "Why are you <%= verbing %> it instead of <%= verbing %> it? Let the <%= noun %> do it.",
54
+ "You're <%= verbing %> the <%= noun %> and <%= verbing %> whatever it <%= verbs %> to the <%= noun %>. You are not <%= verbing %> it when success is <%= verbed %>.",
55
+ "I think there is an issue with the <%= nouns %> themselves; you are <%= verbing %> <%= article noun %> and expecting it to do something.",
56
+ "If the <%= noun %> is just <%= verbing %>, why are you using <%= article noun %> and not <%= article noun %> or <%= article noun %>?",
57
+ "I do not think the <%= noun %> is what you want. If it's <%= adjective %>, then just <%= verb %> it in the <%= adjective %> <%= noun %>.",
58
+ "Without knowing what is happening in the script file, it is hard to give a full answer.",
59
+ "<%= verbing.capitalize %> an <%= adjective %> <%= noun %> is generally a bad idea. Check if the <%= noun %> can access it and do it that way instead.",
60
+ "If I'm not completely missing something here, you'll need to <%= verb %> the <%= adjective %> <%= noun %>.",
61
+ "You have too many <%= nouns %>, which means there is an additional <%= noun %> within the <%= noun %> itself.",
62
+ "Based on the ordering of your <%= nouns %>, you'll want to <%= verb %> the <%= noun %> after the other <%= noun %> was <%= verbed %> instead.",
63
+ "It seems that the <%= noun %> wasn't <%= verbed %> at the right time. Please note that the <%= noun %> is <%= verbed %> once the code has been <%= verbed %> but not necessarily <%= verbed %> first.",
64
+ "You could try reading the documentation about <%= nouns %> in <%= language %>.",
65
+ "At the end of all of your <%= nouns %>, you can <%= verb %> the <%= attribute %> of the <%= noun %>.",
66
+ "It would appear that <%= nouns %> <%= verb %> the <%= noun %> <%= adverb %>.",
67
+ "If you're willing to <%= verb %> <%= adjective %> <%= nouns %>, you could replace them with <%= nouns %>.",
68
+ "If you're using <%= nouns %>, the author of <%= language %> suggests that you use <%= nouns %> instead.",
69
+ "Check the documentation on <%= nouns %>, and see if there's not <%= article noun %> or <%= noun %> you can use to have the <%= noun %> <%= verb %> it automatically.",
70
+ "Double check the error message. It says that it can't <%= verb %> the <%= noun %>, not that it can't <%= verb %> <%= article noun %>.",
71
+ "If your <%= noun %> is <%= article noun %> with <%= article attribute %> property then you can <%= verb %> it with <%= article noun %>, which will <%= verb %> the <%= noun %> and use that as the <%= possessive_noun %> <%= attribute %>.",
72
+ "That <%= possessive_noun %> <%= noun %> was removed from the latest version of <%= language %>, so you can't use it anymore.",
73
+ "By <%= verbing %> <%= article noun %>, we took a <%= noun %> from the <%= noun %> that represents it, and used those <%= nouns %> to signify that it has to <%= verb %> <%= article noun %>. Make sense?",
74
+ "The way you did it here won't work when you want to <%= verb %> <%= nouns %>. A better way is to <%= verb %> any <%= plural type %> in the <%= noun %> that are equal to that <%= type %>."
75
+ ]
76
+
77
+ CONTEXT = {
78
+ noun: [
79
+ # For words that don't follow general english rules, customize them:
80
+ # { singular: "parameter", plural: 'parameters', possessive: "parameter's" },
81
+ { singular: "reference" },
82
+ { singular: "argument" },
83
+ { singular: "parameter" },
84
+ { singular: "loop" },
85
+ { singular: "function" },
86
+ { singular: "variable" },
87
+ { singular: 'method' },
88
+ { singular: 'array' },
89
+ { singular: 'list' },
90
+ { singular: 'statement' },
91
+ { singular: 'object' },
92
+ { singular: 'object literal' },
93
+ { singular: 'array' },
94
+ { singular: 'accessor' },
95
+ { singular: 'return type' },
96
+ { singular: 'instance' },
97
+ { singular: 'element' },
98
+ { singular: 'index', plural: 'indices' },
99
+ { singular: 'dependency' },
100
+ { singular: 'closure' },
101
+ { singular: 'process' },
102
+ ],
103
+ verb: [
104
+ # For words that don't follow general english rules, customize them:
105
+ # { present: 'loop', past: 'looped', gerund: 'looping' },
106
+ { present: 'define' },
107
+ { present: 'pass' },
108
+ { present: 'return' },
109
+ { present: 'process' },
110
+ { present: 'loop' },
111
+ { present: 'initialize' },
112
+ { present: 'iterate' }
113
+ ],
114
+ adjective: [
115
+ 'empty',
116
+ 'illegal',
117
+ 'expected',
118
+ 'unexpected',
119
+ 'nested',
120
+ 'explicit',
121
+ 'implicit',
122
+ 'out of scope',
123
+ 'immutable'
124
+ ],
125
+ adverb: [
126
+ 'asynchronously'
127
+ ],
128
+ attribute: [
129
+ 'length',
130
+ 'name'
131
+ ],
132
+ type: [
133
+ 'boolean',
134
+ 'string',
135
+ 'array',
136
+ 'integer',
137
+ 'hash'
138
+ ],
139
+ language: [
140
+ 'Rails',
141
+ 'Ruby',
142
+ 'Python',
143
+ 'C++',
144
+ 'Java',
145
+ 'JavaScript'
146
+ ]
147
+ }
148
+ end
149
+ end
@@ -0,0 +1,34 @@
1
+ require 'erb'
2
+ require_relative 'render_context'
3
+
4
+ module ProgrammingIpsum
5
+ class Base
6
+ def initialize(phrases, context)
7
+ @phrases = phrases
8
+ @render_context = RenderContext.new(phrases, context)
9
+ end
10
+
11
+ # Render a sequence of phrases for this ipsum
12
+ # Does not guarantee a number of *sentences*, just phrases.
13
+ def sequence(count = 3)
14
+ render @phrases.sample(count).join(" ")
15
+ end
16
+
17
+ # For debugging purposes only - not optimized for general use
18
+ def all_phrases
19
+ width = @phrases.length.to_s.length
20
+
21
+ # twice as fast as string concat!
22
+ input = @phrases.each_with_index.map do |phrase, i|
23
+ i.to_s.rjust(width) + ": " + phrase
24
+ end.join("\n")
25
+
26
+ render(input)
27
+ end
28
+
29
+ private
30
+ def render(input)
31
+ ERB.new(input).result @render_context.binding
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,82 @@
1
+ module ProgrammingIpsum
2
+ module Grammar
3
+ def initialize_grammar
4
+ @inflector = Inflector.new
5
+ end
6
+
7
+ # Catch-all for allowing other keys than :verb and :noun
8
+ def method_missing(key, *args, &block)
9
+ @context.fetch(key, ['INVALID GRAMMAR']).sample
10
+ end
11
+
12
+ # Helper to add an indefinite article to any word
13
+ # Usage:
14
+ # <%= article singular_noun %>
15
+ def article(word)
16
+ @inflector.article(word)
17
+ end
18
+
19
+ # Helper to pluralize any word (based on noun rules)
20
+ # Usage:
21
+ # <%= plural unit_of_measurement %>
22
+ def plural(noun)
23
+ @inflector.plural_noun(noun)
24
+ end
25
+
26
+ # Returns a singular noun like "programmer"
27
+ def singular_noun
28
+ random_noun :singular
29
+ end
30
+
31
+ # Returns a plural noun like "programmers"
32
+ def plural_noun
33
+ random_noun :plural
34
+ end
35
+
36
+ # Returns a possessive noun like "programmer's"
37
+ def possessive_noun
38
+ random_noun :possessive
39
+ end
40
+
41
+ alias :noun :singular_noun
42
+ alias :nouns :plural_noun
43
+ # no alias for possessive_noun, what would it be called?
44
+
45
+ # Returns a present verb, like "render"
46
+ def present_verb
47
+ random_verb :present
48
+ end
49
+
50
+ # Returns an agreement verb (for plural nouns) like "renders"
51
+ def agreement_verb
52
+ random_verb :agreement
53
+ end
54
+
55
+ # Returns a past tense verb like "rendered"
56
+ def past_verb
57
+ random_verb :past
58
+ end
59
+
60
+ # Returns an gerund verb like "rendering"
61
+ def gerund_verb
62
+ random_verb :gerund
63
+ end
64
+
65
+ alias :verb :present_verb
66
+ alias :verbs :agreement_verb
67
+ alias :verbed :past_verb
68
+ alias :verbing :gerund_verb
69
+
70
+ private
71
+
72
+ def random_noun(type)
73
+ noun = @context[:noun].sample
74
+ noun[type] || @inflector.send("#{type}_noun", noun[:singular])
75
+ end
76
+
77
+ def random_verb(type)
78
+ verb = @context[:verb].sample
79
+ verb[type] || @inflector.send("#{type}_verb", verb[:present])
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,84 @@
1
+ # An imperfect but close enough English inflector.
2
+ class ProgrammingIpsum::Inflector
3
+ def article(word)
4
+ if %w{a e i o u}.include?(word[0].downcase)
5
+ "an #{word}"
6
+ else
7
+ "a #{word}"
8
+ end
9
+ end
10
+
11
+ module Noun
12
+ def plural_noun(word)
13
+ if word =~ /(ss|sh|ch|x|o|z)$/
14
+ word + "es"
15
+ elsif word =~ /[aeiou]y$/
16
+ word + "s"
17
+ elsif word[-1] == 'y'
18
+ word[0..-2] + 'ies'
19
+ elsif word =~ /(.*?)(f|fe|ff)$/
20
+ $1 + 'ves'
21
+ else
22
+ word + 's'
23
+ end
24
+ end
25
+
26
+ def possessive_noun(word)
27
+ if word[-1] == 's'
28
+ word + "'"
29
+ else
30
+ word + "'s"
31
+ end
32
+ end
33
+
34
+ def plural_possessive_noun(word)
35
+ possessive_noun(plural_noun(word))
36
+ end
37
+ end
38
+
39
+ # reference http://www.oxforddictionaries.com/words/verb-tenses-adding-ed-and-ing
40
+ module Verb
41
+ # no way to check syllables in ruby, so this has some issues.
42
+ def gerund_verb(word)
43
+ if word =~ /[^oey]e$/
44
+ word[0..-2] + 'ing'
45
+ elsif word[-1] == 'c'
46
+ word + 'king'
47
+ elsif word =~ /[^aeiou][aeiou][^aeiouxw]$/
48
+ word + word[-1] + 'ing'
49
+ else
50
+ word + 'ing'
51
+ end
52
+ end
53
+
54
+ def past_verb(word)
55
+ if word[-1] == 'e'
56
+ word + 'd'
57
+ elsif word[-1] == 'c'
58
+ word + 'ked'
59
+ elsif word =~ /[aeiou][aeiou][^aeiou]$/
60
+ word + 'ed'
61
+ elsif word =~ /[aeiou]([^aeiou])$/
62
+ word + $1 + "ed"
63
+ elsif word =~ /[aeiou]l$/
64
+ word + 'led'
65
+ else
66
+ word + 'ed'
67
+ end
68
+ end
69
+
70
+ # reference http://smrtenglish.com/me/lesson/2531
71
+ def agreement_verb(word)
72
+ if word =~ /(ss|sh|ch|x|o|z)$/
73
+ word + 'es'
74
+ elsif word =~ /[^aeiou]y$/
75
+ word[0..-2] + 'ies'
76
+ else
77
+ word + 's'
78
+ end
79
+ end
80
+ end
81
+
82
+ include Noun
83
+ include Verb
84
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'grammar'
2
+ require_relative 'inflector'
3
+
4
+ module ProgrammingIpsum
5
+ class RenderContext < BasicObject
6
+ include Grammar
7
+ attr_accessor :phrases, :context
8
+
9
+ def initialize(phrases, context)
10
+ @phrases = phrases
11
+ @context = context
12
+ initialize_grammar
13
+ end
14
+
15
+ def binding
16
+ ::Kernel.binding
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ProgrammingIpsum
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "programming_ipsum/version"
2
+ require "programming_ipsum/advice_ipsum"
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'programming_ipsum/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "programming_ipsum"
8
+ spec.version = ProgrammingIpsum::VERSION
9
+ spec.authors = ["bbugh"]
10
+ spec.email = ["nothanks@whatever.com"]
11
+
12
+ spec.summary = "Programming Ipsum to output intelligent and useful advice on programming."
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://www.github.com/bbugh/programming_ipsum"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry"
34
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: programming_ipsum
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - bbugh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-07 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - nothanks@whatever.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/programming_ipsum.rb
86
+ - lib/programming_ipsum/advice_ipsum.rb
87
+ - lib/programming_ipsum/base.rb
88
+ - lib/programming_ipsum/grammar.rb
89
+ - lib/programming_ipsum/inflector.rb
90
+ - lib/programming_ipsum/render_context.rb
91
+ - lib/programming_ipsum/version.rb
92
+ - programming_ipsum.gemspec
93
+ homepage: https://www.github.com/bbugh/programming_ipsum
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Programming Ipsum to output intelligent and useful advice on programming.
117
+ test_files: []
118
+ has_rdoc: