faker-isbn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/Rakefile +8 -0
- data/faker-isbn.gemspec +22 -0
- data/lib/faker-isbn.rb +31 -0
- data/lib/faker-isbn/version.rb +5 -0
- data/spec/isbn_spec.rb +13 -0
- data/spec/spec_helper.rb +4 -0
- metadata +67 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/faker-isbn.gemspec
ADDED
@@ -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
|
data/spec/isbn_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
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
|