faker-isbn 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in faker-i.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ faker-isbn
2
+ ==========
3
+
4
+ faker-isbn
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Run Rspecs"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "faker-isbn/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "faker-isbn"
7
+ s.version = Faker::ISBN::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nick Zalabak"]
10
+ s.email = ["techwhizbang@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Generates fake 13 digit ISBN's for your test suite/database}
13
+ s.description = %q{A faker extension that generates 13 digit ISBN's for your test suite/database}
14
+
15
+ s.rubyforge_project = "faker-isbn"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.add_dependency(%q<bookland>, ["~> 2.0.0"])
22
+ end
data/lib/faker-isbn.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'bookland'
3
+
4
+ module Faker
5
+ class ISBN
6
+ @thirteen_digit_multipliers = [1, 3]
7
+ @thirteen_digit_modulo = 10
8
+
9
+ def self.thirteen_digit
10
+ isbn_13 = ""
11
+ until Bookland::ISBN.new(isbn_13).valid? do
12
+ isbn_digit_array = [9, 7, 8]
13
+ (1..9).each { isbn_digit_array << rand(10) }
14
+ isbn_digit_array << calculate_thirteenth_check_digit(isbn_digit_array)
15
+ isbn_13 = isbn_digit_array.join
16
+ end
17
+ isbn_13
18
+ end
19
+
20
+ private
21
+
22
+ def self.calculate_thirteenth_check_digit(twelve_digit_array)
23
+ sum = 0
24
+ twelve_digit_array.each_with_index do |digit, index|
25
+ multiplier = (index % 2 == 0) ? @thirteen_digit_multipliers[0] : @thirteen_digit_multipliers[1]
26
+ sum += digit * multiplier
27
+ end
28
+ @thirteen_digit_modulo - (sum % @thirteen_digit_modulo)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Faker
2
+ module ISBN
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/spec/isbn_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faker::ISBN do
4
+
5
+ describe "#thirteen_digit" do
6
+
7
+ it 'generates a valid 13 digit ISBN' do
8
+ 20.times { Bookland::ISBN.new(Faker::ISBN.thirteen_digit).valid?.should be_true }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/faker-isbn")
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faker-isbn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Zalabak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bookland
16
+ requirement: &70121070842280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70121070842280
25
+ description: A faker extension that generates 13 digit ISBN's for your test suite/database
26
+ email:
27
+ - techwhizbang@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - faker-isbn.gemspec
37
+ - lib/faker-isbn.rb
38
+ - lib/faker-isbn/version.rb
39
+ - spec/isbn_spec.rb
40
+ - spec/spec_helper.rb
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: faker-isbn
61
+ rubygems_version: 1.8.10
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Generates fake 13 digit ISBN's for your test suite/database
65
+ test_files:
66
+ - spec/isbn_spec.rb
67
+ - spec/spec_helper.rb