Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bank setup #762

Merged
merged 3 commits into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Contents
- [Faker::Address](#fakeraddress)
- [Faker::Bitcoin](#fakerbitcoin)
- [Faker::Business](#fakerbusiness)
- [Faker::Bank](#fakerbank)
- [Faker::Code](#fakercode)
- [Faker::Color](#fakercolor)
- [Faker::Commerce](#fakercommerce)
Expand Down Expand Up @@ -143,6 +144,23 @@ Faker::Business.credit_card_type #=> "visa"

```

###Faker::Bank
------------------

```ruby

Faker::Bank.name #=> "ABN AMRO CORPORATE FINANCE LIMITED"

Faker::Bank.bic_swift #=> "AAFMGB21"

Faker::Bank.iban #=> "GB76DZJM33188515981979"

# Optional argument bank_country_code(EU only)
Faker::Bank.iban("be") #=> "BE6375388567752043"

```


###Faker::Code
--------------

Expand Down
1 change: 1 addition & 0 deletions lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def rand_in_range(from, to)
require 'faker/game_of_thrones'
require 'faker/pokemon'
require 'faker/food'
require 'faker/bank'
require 'faker/ancient'

require 'extensions/array'
Expand Down
30 changes: 30 additions & 0 deletions lib/faker/bank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Faker
class Bank < Base
flexible :bank

class << self
def name
fetch('bank.name')
end

def swift_bic
fetch('bank.swift_bic')
end

def iban(bank_country_code="GB")
details = iban_details.find { |country| country["bank_country_code"] == bank_country_code.upcase }
bcc = details["bank_country_code"] + 2.times.map{ rand(10) }.join
ilc = (0...details["iban_letter_code"].to_i).map{ (65 + rand(26)).chr }.join
ib = details["iban_digits"].to_i.times.map{ rand(10) }.join
bcc + ilc + ib
end

private

def iban_details
fetch_all('bank.iban_details')
end
end
end
end

86 changes: 86 additions & 0 deletions lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,92 @@ en:
publisher: ["Academic Press", "Ace Books", "Addison-Wesley", "Adis International", "Airiti Press", "André Deutsch", "Andrews McMeel Publishing", "Anova Books", "Anvil Press Poetry", "Applewood Books", "Apress", "Athabasca University Press", "Atheneum Books", "Atheneum Publishers", "Atlantic Books", "Atlas Press", "Ballantine Books", "Banner of Truth Trust", "Bantam Books", "Bantam Spectra", "Barrie & Jenkins", "Basic Books", "BBC Books", "Harvard University Press", "Belknap Press", "Bella Books", "Bellevue Literary Press", "Berg Publishers", "Berkley Books", "Bison Books", "Black Dog Publishing", "Black Library", "Black Sparrow Books", "Blackie and Son Limited", "Blackstaff Press", "Blackwell Publishing", "John Blake Publishing", "Bloodaxe Books", "Bloomsbury Publishing Plc", "Blue Ribbon Books", "Book League of America", "Book Works", "Booktrope", "Borgo Press", "Bowes & Bowes", "Boydell & Brewer", "Breslov Research Institute", "Brill Publishers", "Brimstone Press", "Broadview Press", "Burns & Oates", "Butterworth-Heinemann", "Caister Academic Press", "Cambridge University Press", "Candlewick Press", "Canongate Books", "Carcanet Press", "Carlton Books", "Carlton Publishing Group", "Carnegie Mellon University Press", "Casemate Publishers", "Cengage Learning", "Central European University Press", "Chambers Harrap", "Charles Scribner's Sons", "Chatto and Windus", "Chick Publications", "Chronicle Books", "Churchill Livingstone", "Cisco Press", "City Lights Publishers", "Cloverdale Corporation", "D. Appleton & Company", "D. Reidel", "Da Capo Press", "Daedalus Publishing", "Dalkey Archive Press", "Darakwon Press", "David & Charles", "DAW Books", "Dedalus Books", "Del Rey Books", "E. P. Dutton", "Earthscan", "ECW Press", "Eel Pie Publishing", "Eerdmans Publishing", "Edupedia Publications", "Ellora's Cave", "Elsevier", "Emerald Group Publishing", "Etruscan Press", "Faber and Faber", "FabJob", "Fairview Press", "Farrar, Straus & Giroux", "Fearless Books", "Felony & Mayhem Press", "Firebrand Books", "Flame Tree Publishing", "Focal Press", "G. P. Putnam's Sons", "G-Unit Books", "Gaspereau Press", "Gay Men's Press", "Gefen Publishing House", "George H. Doran Company", "George Newnes", "George Routledge & Sons", "Godwit Press", "Golden Cockerel Press", "Hachette Book Group USA", "Hackett Publishing Company", "Hamish Hamilton", "Happy House", "Harcourt Assessment", "Harcourt Trade Publishers", "Harlequin Enterprises Ltd", "Harper & Brothers", "Harper & Row", "HarperCollins", "HarperPrism", "HarperTrophy", "Harry N. Abrams, Inc.", "Harvard University Press", "Harvest House", "Harvill Press at Random House", "Hawthorne Books", "Hay House", "Haynes Manuals", "Heyday Books", "HMSO", "Hodder & Stoughton", "Hodder Headline", "Hogarth Press", "Holland Park Press", "Holt McDougal", "Horizon Scientific Press", "Ian Allan Publishing", "Ignatius Press", "Imperial War Museum", "Indiana University Press", "J. M. Dent", "Jaico Publishing House", "Jarrolds Publishing", "Karadi Tales", "Kensington Books", "Kessinger Publishing", "Kodansha", "Kogan Page", "Koren Publishers Jerusalem", "Ladybird Books", "Leaf Books", "Leafwood Publishers", "Left Book Club", "Legend Books", "Lethe Press", "Libertas Academica", "Liberty Fund", "Library of America", "Lion Hudson", "Macmillan Publishers", "Mainstream Publishing", "Manchester University Press", "Mandrake of Oxford", "Mandrake Press", "Manning Publications", "Manor House Publishing", "Mapin Publishing", "Marion Boyars Publishers", "Mark Batty Publisher", "Marshall Cavendish", "Marshall Pickering", "Martinus Nijhoff Publishers", "Mascot Books", "Matthias Media", "McClelland and Stewart", "McFarland & Company", "McGraw-Hill Education", "McGraw Hill Financial", "Medknow Publications", "Naiad Press", "Nauka", "NavPress", "New Directions Publishing", "New English Library", "New Holland Publishers", "New Village Press", "Newnes", "No Starch Press", "Nonesuch Press", "Oberon Books", "Open Court Publishing Company", "Open University Press", "Orchard Books", "O'Reilly Media", "Orion Books", "Packt Publishing", "Palgrave Macmillan", "Pan Books", "Pantheon Books at Random House", "Papadakis Publisher", "Parachute Publishing", "Parragon", "Pathfinder Press", "Paulist Press", "Pavilion Books", "Peace Hill Press", "Pecan Grove Press", "Pen and Sword Books", "Penguin Books", "Random House", "Reed Elsevier", "Reed Publishing", "SAGE Publications", "St. Martin's Press", "Salt Publishing", "Sams Publishing", "Schocken Books", "Scholastic Press", "Charles Scribner's Sons", "Seagull Books", "Secker & Warburg", "Shambhala Publications", "Shire Books", "Shoemaker & Hoard Publishers", "Shuter & Shooter Publishers", "Sidgwick & Jackson", "Signet Books", "Simon & Schuster", "T & T Clark", "Tachyon Publications", "Tammi", "Target Books", "Tarpaulin Sky Press", "Tartarus Press", "Tate Publishing & Enterprises", "Taunton Press", "Taylor & Francis", "Ten Speed Press", "UCL Press", "Unfinished Monument Press", "United States Government Publishing Office", "University of Akron Press", "University of Alaska Press", "University of California Press", "University of Chicago Press", "University of Michigan Press", "University of Minnesota Press", "University of Nebraska Press", "Velazquez Press", "Verso Books", "Victor Gollancz Ltd", "Viking Press", "Vintage Books", "Vintage Books at Random House", "Virago Press", "Virgin Publishing", "Voyager Books", "Brill", "Allen Ltd", "Zed Books", "Ziff Davis Media", "Zondervan"]
genre: ['Classic', 'Comic/Graphic Novel', 'Crime/Detective', 'Fable', 'Fairy tale', 'Fanfiction', 'Fantasy', 'Fiction narrative', 'Fiction in verse', 'Folklore', 'Historical fiction', 'Horror', 'Humor', 'Legend', 'Metafiction', 'Mystery', 'Mythology', 'Mythopoeia', 'Realistic fiction', 'Science fiction', 'Short story', 'Suspense/Thriller', 'Tall tale', 'Western', 'Biography/Autobiography', 'Essay', 'Narrative nonfiction', 'Speech', 'Textbook', 'Reference book']

bank:
name: ["UBS CLEARING AND EXECUTION SERVICES LIMITED", "ABN AMRO CORPORATE FINANCE LIMITED", "ABN AMRO FUND MANAGERS LIMITED", "ABN AMRO HOARE GOVETT SECURITIES", "ABN AMRO HOARE GOVETT CORPORATE FINANCE LTD.", "ALKEN ASSET MANAGEMENT", "ALKEN ASSET MANAGEMENT", "ABN AMRO HOARE GOVETT LIMITED", "AAC CAPITAL PARTNERS LIMITED", "ABBOTSTONE AGRICULTURAL PROPERTY UNIT TRUST", "ABN AMRO QUOTED INVESTMENTS (UK) LIMITED", "ABN AMRO MEZZANINE (UK) LIMITED", "ABBEY LIFE", "SANTANDER UK PLC", "OTKRITIE SECURITIES LIMITED", "ABC INTERNATIONAL BANK PLC", "ALLIED BANK PHILIPPINES (UK) PLC", "ABU DHABI ISLAMIC BANK", "ABG SUNDAL COLLIER LIMITED", "PGMS (GLASGOW) LIMITED", "ABINGWORTH MANAGEMENT LIMITED", "THE ROYAL BANK OF SCOTLAND PLC (FORMER RBS NV)"]
swift_bic: ["AACCGB21", "AACNGB21", "AAFMGB21", "AAHOGB21", "AAHVGB21", "AANLGB21", "AANLGB2L", "AAOGGB21", "AAPEGB21", "AAPUGB21", "AAQIGB21", "ABAZGB21", "ABBEGB21", "ABBYGB2L", "ABCCGB22", "ABCEGB2L", "ABCMGB21", "ABDIGB21", "ABECGB21", "ABFIGB21", "ABMNGB21", "ABNAGB21VOC" ]
iban_details:
- bank_country_code: "AT"
iban_letter_code: '0'
iban_digits: '18'
- bank_country_code: "BG"
iban_letter_code: '4'
iban_digits: '14'
- bank_country_code: "BE"
iban_letter_code: '0'
iban_digits: '14'
- bank_country_code: "CY"
iban_letter_code: '0'
iban_digits: '26'
- bank_country_code: "CZ"
iban_letter_code: '0'
iban_digits: '22'
- bank_country_code: "DE"
iban_letter_code: '0'
iban_digits: '20'
- bank_country_code: "DK"
iban_letter_code: '0'
iban_digits: '16'
- bank_country_code: "EE"
iban_letter_code: '0'
iban_digits: '18'
- bank_country_code: "ES"
iban_letter_code: '0'
iban_digits: '22'
- bank_country_code: "FI"
iban_letter_code: '0'
iban_digits: '16'
- bank_country_code: "FR"
iban_letter_code: '0'
iban_digits: '25'
- bank_country_code: "GB"
iban_letter_code: '4'
iban_digits: '14'
- bank_country_code: "GR"
iban_letter_code: '0'
iban_digits: '25'
- bank_country_code: "HU"
iban_letter_code: '0'
iban_digits: '28'
- bank_country_code: "HR"
iban_letter_code: '0'
iban_digits: '19'
- bank_country_code: "IE"
iban_letter_code: '4'
iban_digits: '16'
- bank_country_code: "IT"
iban_letter_code: '0'
iban_digits: '25'
- bank_country_code: "LV"
iban_letter_code: '4'
iban_digits: '15'
- bank_country_code: "LT"
iban_letter_code: '0'
iban_digits: '14'
- bank_country_code: "LU"
iban_letter_code: '0'
iban_digits: '16'
- bank_country_code: "PL"
iban_letter_code: '0'
iban_digits: '24'
- bank_country_code: "PT"
iban_letter_code: '0'
iban_digits: '18'
- bank_country_code: "MT"
iban_letter_code: '4'
iban_digits: '26'
- bank_country_code: "NL"
iban_letter_code: '4'
iban_digits: '12'
- bank_country_code: "RO"
iban_letter_code: '4'
iban_digits: '18'
- bank_country_code: "SE"
iban_letter_code: '0'
iban_digits: '22'
- bank_country_code: "SK"
iban_letter_code: '0'
iban_digits: '22'

cat:
name: ["Alfie", "Angel", "Bella", "Charlie", "Chloe", "Coco", "Daisy", "Felix", "Jasper", "Lily", "Lucky", "Lucy", "Max", "Millie", "Milo", "Missy", "Misty", "Molly", "Oliver", "Oscar", "Poppy", "Sam", "Shadow", "Simba", "Smokey", "Smudge", "Sooty", "Tiger"]
breed: ["Abyssinian", "Aegean", "American Bobtail", "American Curl", "American Shorthair", "American Wirehair", "Arabian Mau", "Asian", "Asian Semi-longhair", "Australian Mist", "Balinese", "Bambino", "Bengal", "Birman", "Bombay", "Brazilian Shorthair", "British Longhair", "British Semipi-longhair", "British Shorthair", "Burmese", "Burmilla", "California Spangled", "Chantilly-Tiffany", "Chartreux", "Chausie", "Cheetoh", "Colorpoint Shorthair", "Cornish Rex", "Cymric, or Manx Longhair", "Cyprus", "Devon Rex", "Donskoy, or Don Sphynx", "Dragon Li", "Dwarf cat, or Dwelf", "Egyptian Mau", "European Shorthair", "Exotic Shorthair", "Foldex Cat", "German Rex", "Havana Brown", "Highlander", "Himalayan, or Colorpoint Persian", "Japanese Bobtail", "Javanese", "Khao Manee", "Korat", "Korean Bobtail", "Korn Ja", "Kurilian Bobtail", "Kurilian Bobtail, or Kuril Islands Bobtail", "LaPerm", "Lykoi", "Maine Coon", "Manx", "Mekong Bobtail", "Minskin", "Munchkin", "Napoleon", "Nebelung", "Norwegian Forest Cat", "Ocicat", "Ojos Azules", "Oregon Rex", "Oriental Bicolor", "Oriental Longhair", "Oriental Shorthair", "PerFold Cat (Experimental Breed - WCF)", "Persian (Modern Persian Cat)", "Persian (Traditional Persian Cat)", "Peterbald", "Pixie-bob", "Raas", "Ragamuffin", "Ragdoll", "Russian Blue", "Russian White, Black and Tabby", "Sam Sawet", "Savannah", "Scottish Fold", "Selkirk Rex", "Serengeti", "Serrade petit", "Siamese", "Siberian", "Singapura", "Snowshoe", "Sokoke", "Somali", "Sphynx", "Suphalak", "Thai", "Tonkinese", "Toyger", "Turkish Angora", "Turkish Van", "Ukrainian Levkoy"]
Expand Down
50 changes: 50 additions & 0 deletions test/test_faker_bank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')

class TestFakerBank < Test::Unit::TestCase

def setup
@tester = Faker::Bank
end

def test_name
assert @tester.name.match(/(\w+\.? ?){2,3}/)
end

def test_swift_bic
assert @tester.swift_bic.match(/(\w+\.? ?){2,3}/)
end

def test_iban_default; assert @tester.iban.match(/[A-Z]{4}\d{14}/); end
def test_iban_at; assert @tester.iban("at").match(/\d{16}/); end
def test_iban_pl; assert @tester.iban("pl").match(/\d{8}[A-Z0-9]{16}/); end
def test_iban_be; assert @tester.iban("be").match(/\d{12}/); end
def test_iban_bg; assert @tester.iban("bg").match(/[A-Z]{4}\d{6}[A-Z0-9]{8}/); end
def test_iban_hr; assert @tester.iban("hr").match(/\d{17}/); end
def test_iban_cy; assert @tester.iban("cy").match(/\d{8}[A-Z0-9]{16}/); end
def test_iban_cz; assert @tester.iban("cz").match(/\d{20}/); end
def test_iban_dk; assert @tester.iban("dk").match(/\d{14}/); end
def test_iban_ee; assert @tester.iban("ee").match(/\d{16}/); end
def test_iban_fi; assert @tester.iban("fi").match(/\d{14}/); end
def test_iban_fr; assert @tester.iban("fr").match(/\d{10}[A-Z0-9]{11}\d{2}/); end
def test_iban_de; assert @tester.iban("de").match(/\d{18}/); end
def test_iban_gr; assert @tester.iban("gr").match(/\d{7}[A-Z0-9]{16}/); end
def test_iban_hu; assert @tester.iban("hu").match(/\d{24}/); end
def test_iban_ie; assert @tester.iban("ie").match(/[A-Z]{4}\d{14}/); end
def test_iban_it; assert @tester.iban("it").match(/[A-Z]\d{10}[A-Z0-9]{12}/); end
def test_iban_lv; assert @tester.iban("lv").match(/[A-Z]{4}[A-Z0-9]{13}/); end
def test_iban_lt; assert @tester.iban("lt").match(/\d{16}/); end
def test_iban_lu; assert @tester.iban("lu").match(/\d{3}[A-Z0-9]{13}/); end
def test_iban_mt; assert @tester.iban("mt").match(/[A-Z]{4}\d{5}[A-Z0-9]{18}/); end
def test_iban_nl; assert @tester.iban("nl").match(/[A-Z]{4}\d{10}/); end
def test_iban_ro; assert @tester.iban("ro").match(/[A-Z]{4}[A-Z0-9]{16}/); end
def test_iban_es; assert @tester.iban("es").match(/\d{20}/); end
def test_iban_se; assert @tester.iban("se").match(/\d{20}/); end
def test_iban_sk; assert @tester.iban("sk").match(/\d{24}/); end
end