Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

re-organization for cleanliness

  • Loading branch information...
commit b6f71dd3b422cc7d4462d3ea7ab6f9c0523bbb2e 1 parent c8ec357
James OKelly authored
View
62 lib/generator.rb
@@ -1,62 +0,0 @@
-require 'json'
-require "version"
-
-$:.unshift(File.dirname(__FILE__)+'/lib')
-
-module RomanNameGenerator
- class Generator
- attr_accessor :name_data, :gender, :result, :type
-
- def initialize(gender)
- self.gender = gender
- self.result = random_name.strip
- end
-
- private
-
- def random_name
- load_name_data if self.name_data.nil?
- [random_first_name, random_middle_name, random_last_name].join(" ")
- end
-
- def random_first_name
- case self.gender
- when "male"
- data = self.name_data['praenomens']
- data[rand(data.length)]
- when "female"
- data = self.name_data['nomens']['female']
- data[rand(data.length)]
- end
- end
-
- def random_middle_name
- case self.gender
- when "male"
- data = self.name_data['nomens']['male']
- data[rand(data.length)]
- when "female"
- ""
- end
- end
-
- def random_last_name
- case self.gender
- when "male"
- data = self.name_data['cognomens']['male']
- data[rand(data.length)]
- when "female"
- data = self.name_data['cognomens']['female']
- data[rand(data.length)]
- end
- end
-
- def load_name_data
- self.name_data = JSON(
- File.open(
- File.expand_path("../data/names.json", __FILE__)
- ).read
- )
- end
- end
-end
View
65 lib/roman_name_generator.rb
@@ -0,0 +1,65 @@
+require 'json'
+require "version"
+
+$:.unshift(File.dirname(__FILE__)+'/lib')
+
+class RomanNameGenerator
+
+ def self.version
+ "0.1.0"
+ end
+
+ attr_accessor :name_data, :gender, :result, :type
+
+ def initialize(gender)
+ self.gender = gender
+ self.result = random_name.strip
+ end
+
+private
+
+ def random_name # :nodoc:
+ load_name_data if self.name_data.nil?
+ [random_first_name, random_middle_name, random_last_name].join(" ")
+ end
+
+ def random_first_name # :nodoc:
+ case self.gender
+ when "male"
+ data = self.name_data['praenomens']
+ data[rand(data.length)]
+ when "female"
+ data = self.name_data['nomens']['female']
+ data[rand(data.length)]
+ end
+ end
+
+ def random_middle_name # :nodoc:
+ case self.gender
+ when "male"
+ data = self.name_data['nomens']['male']
+ data[rand(data.length)]
+ when "female"
+ ""
+ end
+ end
+
+ def random_last_name # :nodoc:
+ case self.gender
+ when "male"
+ data = self.name_data['cognomens']['male']
+ data[rand(data.length)]
+ when "female"
+ data = self.name_data['cognomens']['female']
+ data[rand(data.length)]
+ end
+ end
+
+ def load_name_data # :nodoc:
+ self.name_data = JSON(
+ File.open(
+ File.expand_path("../data/names.json", __FILE__)
+ ).read
+ )
+ end
+end
View
3  lib/version.rb
@@ -1,3 +0,0 @@
-module RomanNameGenerator
- VERSION = "0.1.0"
-end
View
4 roman-name-generator.gemspec
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/version', __FILE__)
+require File.expand_path('../lib/roman_name_generator', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["James OKelly"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "roman-name-generator"
gem.require_paths = ["lib"]
- gem.version = RomanNameGenerator::VERSION
+ gem.version = RomanNameGenerator.version
gem.add_development_dependency('rake')
gem.add_development_dependency('minitest')
View
2  test/_shared_examples/male_roman_name_test.rb
@@ -3,7 +3,7 @@
shared_examples_for 'a male roman name' do
describe "Generator" do
before do
- @subject = RomanNameGenerator::Generator.new("male")
+ @subject = RomanNameGenerator.new("male")
end
describe "#load_name_data" do
View
2  test/lib/generator_test.rb → test/lib/roman_name_generator_test.rb
@@ -1,6 +1,6 @@
require 'minitest_helper'
-describe RomanNameGenerator::Generator do
+describe RomanNameGenerator do
it_must_behave_like 'a male roman name'
Please sign in to comment.
Something went wrong with that request. Please try again.