namazing 0.0.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.
@@ -0,0 +1,52 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Namazing
4
+
5
+ class Wordup
6
+
7
+ attr_accessor :boring, :awesomes
8
+
9
+ def initialize boring
10
+ @boring = boring
11
+ @awesomes = []
12
+ raise ArgumentError, "Wordup requires a string" if @boring.class.name != "String"
13
+ end
14
+
15
+ def split
16
+ if type == :underscore
17
+ return @boring.split("_")
18
+ else
19
+ return @boring.split /(?=[A-Z])/
20
+ end
21
+ end
22
+
23
+ def awesome
24
+ result = @awesomes.join("_")
25
+ if type == :camelcase
26
+ return result.camelize(:lower)
27
+ elsif type == :pascalcase
28
+ return result.camelize
29
+ end
30
+ result
31
+ end
32
+
33
+ def word_count
34
+ @boring.underscore.split("_").length
35
+ end
36
+
37
+ def type
38
+ return :underscore if @boring =~ /_/
39
+ if @boring =~ /[A-Z]+/
40
+ if @boring[0] =~ /[A-Z]/
41
+ return :pascalcase
42
+ else
43
+ return :camelcase
44
+ end
45
+ else
46
+ return :underscore
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
data/lib/namazing.rb ADDED
@@ -0,0 +1,4 @@
1
+ require './lib/namazing/namazing.rb'
2
+
3
+ module Namazing
4
+ end
data/namazing.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ require File.expand_path("../lib/namazing/namazing", __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "namazing"
5
+ gem.version = Namazing.version
6
+ gem.author = "Dan Harper"
7
+ gem.email = "dan@kingdomsolutions.com.au"
8
+ gem.description = gem.summary = "Name things with more awesome."
9
+ gem.homepage = "https://github.com/dmuso/namazing"
10
+
11
+ gem.add_runtime_dependency 'activesupport', '~> 4.0'
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ["lib"]
16
+
17
+ gem.license = 'Apache 2.0'
18
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Namazing do
4
+
5
+ describe "#random" do
6
+
7
+ subject { Namazing.random }
8
+
9
+ it "should provide a string" do
10
+ expect(subject).to be_a_kind_of(String)
11
+ end
12
+
13
+ it "should provide a word longer than 3 characters" do
14
+ expect(subject.size).to be > 3
15
+ end
16
+
17
+ it "should provide one word when no parameters are provided" do
18
+ expect(subject.downcase).to match(/[a-z]+/)
19
+ end
20
+
21
+ it "should provide a random word" do
22
+ srand(10)
23
+ expect(subject).to eq("netminders")
24
+ end
25
+
26
+ end
27
+
28
+ describe "#convert" do
29
+
30
+ subject { Namazing.convert "boring" }
31
+
32
+ it "should be a string" do
33
+ expect(subject).to be_a_kind_of(String)
34
+ end
35
+
36
+ it "should provide a word longer than 3 characters" do
37
+ expect(subject.size).to be > 3
38
+ end
39
+
40
+ it "should not be boring" do
41
+ expect(subject).not_to eq("boring")
42
+ end
43
+
44
+ it "should return the same awesome for the same boring" do
45
+ first = subject
46
+ expect(subject).to eq (first)
47
+ end
48
+
49
+ it "should return a different awesome with a different boring" do
50
+ first = subject
51
+ expect(Namazing.convert "slightlyboring").not_to eq (first)
52
+ end
53
+
54
+ end
55
+
56
+ describe "#to_awesome" do
57
+
58
+ subject { Namazing.to_awesome "boring" }
59
+
60
+ it "should be a string" do
61
+ expect(subject).to be_a_kind_of(String)
62
+ end
63
+
64
+ it "should not be boring" do
65
+ expect(subject).not_to eq("boring")
66
+ end
67
+
68
+ it "should return a multiword awesome if given a multiword boring" do
69
+ expect(Namazing.to_awesome("super_boring").split("_").length).to eq 2
70
+ end
71
+
72
+ it "should give the same awesome regardless of case" do
73
+ first = subject
74
+ expect(Namazing.to_awesome("Boring").downcase).to eq(first.downcase)
75
+ end
76
+
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module Namazing
4
+
5
+ describe Wordup do
6
+
7
+ describe "#initialize" do
8
+
9
+ it "should require a string" do
10
+ expect{Wordup.new(nil)}.to raise_error(ArgumentError)
11
+ expect{Wordup.new(1)}.to raise_error(ArgumentError)
12
+ expect{Wordup.new("boring")}.not_to raise_error
13
+ end
14
+
15
+ end
16
+
17
+ describe "#word_count" do
18
+
19
+ it "should return the correct number of words" do
20
+ expect(Wordup.new("very_very_extremely_boring").word_count).to eq 4
21
+ end
22
+
23
+ it "should handle CamelCase" do
24
+ expect(Wordup.new("VeryBoringName").word_count).to eq 3
25
+ end
26
+
27
+ it "should handle camelCase" do
28
+ expect(Wordup.new("veryBoringName").word_count).to eq 3
29
+ end
30
+ end
31
+
32
+ describe "#type" do
33
+
34
+ it "should identify underscore" do
35
+ expect(Wordup.new("very_very_extremely_boring").type).to eq :underscore
36
+ end
37
+
38
+ it "should identify PascalCase" do
39
+ expect(Wordup.new("VeryBoringName").type).to eq :pascalcase
40
+ end
41
+
42
+ it "should identify camelCase" do
43
+ expect(Wordup.new("veryBoringName").type).to eq :camelcase
44
+ end
45
+ end
46
+
47
+ describe "#split" do
48
+
49
+ it "should split underscore" do
50
+ expect(Wordup.new("very_very_extremely_boring").split.length).to eq 4
51
+ end
52
+
53
+ it "should split CamelCase" do
54
+ expect(Wordup.new("VeryBoringName").split.length).to eq 3
55
+ end
56
+
57
+ it "should split camelCase" do
58
+ expect(Wordup.new("veryBoringName").split.length).to eq 3
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'rake'
3
+
4
+ Dir[File.expand_path("../../lib/**/*.rb", __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namazing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dan Harper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ description: Name things with more awesome.
28
+ email: dan@kingdomsolutions.com.au
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - ".ruby-version"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/namazing.rb
42
+ - lib/namazing/namazing.rb
43
+ - lib/namazing/word_list_filtered.txt
44
+ - lib/namazing/wordup.rb
45
+ - namazing.gemspec
46
+ - spec/lib/namazing/namazing_spec.rb
47
+ - spec/lib/namazing/wordup_spec.rb
48
+ - spec/spec_helper.rb
49
+ homepage: https://github.com/dmuso/namazing
50
+ licenses:
51
+ - Apache 2.0
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.2.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Name things with more awesome.
73
+ test_files:
74
+ - spec/lib/namazing/namazing_spec.rb
75
+ - spec/lib/namazing/wordup_spec.rb
76
+ - spec/spec_helper.rb