1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00

add finance & Data

This commit is contained in:
Aşkın Gedik 2016-01-12 08:57:54 +02:00
parent 0ad1c1c623
commit e45011e955
6 changed files with 329 additions and 130 deletions

218
README.md
View File

@ -24,116 +24,204 @@ Faker::Name.name
### Faker::Address
```crystal
Faker::Address.city
Faker::Address.street_name
Faker::Address.street_address
Faker::Address.secondary_address
Faker::Address.building_number
Faker::Address.zip_code
Faker::Address.postcode
Faker::Address.time_zone
Faker::Address.street_suffix
Faker::Address.city_suffix
Faker::Address.city_prefix
Faker::Address.state
Faker::Address.state_abbr
Faker::Address.country
Faker::Address.city #=> "Imogeneborough"
Faker::Address.latitude
Faker::Address.longitude
Faker::Address.street_name #=> "Larkin Fork"
Faker::Address.street_address #=> "282 Kevin Brook"
Faker::Address.secondary_address #=> "Apt. 672"
Faker::Address.building_number #=> "7304"
Faker::Address.zip_code #=> "58517"
Faker::Address.postcode #=> "58517"
Faker::Address.time_zone #=> "Asia/Yakutsk"
Faker::Address.street_suffix #=> "Street"
Faker::Address.city_suffix #=> "fort"
Faker::Address.city_prefix #=> "Lake"
Faker::Address.state #=> "California"
Faker::Address.state_abbr #=> "AP"
Faker::Address.country #=> "French Guiana"
Faker::Address.latitude #=> "-58.17256227443719"
Faker::Address.longitude #=> "-156.65548382095133"
```
### Faker::Business
------------------
```crystal
Faker::Business.credit_card_number #=> "1228-1221-1221-1431"
Faker::Business.credit_card_expiry_date #=> <Time: 2015-11-11>
Faker::Business.credit_card_type #=> "visa"
```
### Faker::Commerce
```crystal
Faker::Commerce.color
Faker::Commerce.department
Faker::Commerce.product_name
Faker::Commerce.price
Faker::Commerce.color #=> "lavender"
Faker::Commerce.department #=> "Grocery, Health & Beauty"
Faker::Commerce.product_name #=> "Practical Granite Shirt"
Faker::Commerce.price #=> "44.6"
```
### Faker::Company
```crystal
Faker::Company.name
Faker::Company.suffix
Faker::Company.name #=> "Hirthe-Ritchie"
Faker::Company.suffix #=> "Group"
```
### Faker::Internet
```crystal
Faker::Internet.email
Faker::Internet.email("Nancy")
Faker::Internet.free_email
Faker::Internet.free_email("Nancy")
Faker::Internet.safe_email
Faker::Internet.safe_email("Nancy")
Faker::Internet.user_name
Faker::Internet.user_name("Nancy")
Faker::Internet.user_name("Nancy Johnson", %w(. _ -))
# Optional argument name=nil
Faker::Internet.email #=> "eliza@mann.net"
Faker::Internet.domain_name
Faker::Internet.domain_word
Faker::Internet.domain_suffix
Faker::Internet.email('Nancy') #=> "nancy@terry.biz"
Faker::Internet.ip_v4_address
# Optional argument name=nil
Faker::Internet.free_email #=> "freddy@gmail.com"
Faker::Internet.free_email('Nancy') #=> "nancy@yahoo.com"
# Optional argument name=nil
Faker::Internet.safe_email #=> "christelle@example.org"
Faker::Internet.safe_email('Nancy') #=> "nancy@example.net"
# Optional arguments specifier=nil, separators=%w(. _)
Faker::Internet.user_name #=> "alexie"
Faker::Internet.user_name('Nancy') #=> "nancy"
Faker::Internet.user_name('Nancy Johnson', %w(. _ -)) #=> "johnson-nancy"
# Optional argument min_length=0
Faker::Internet.password #=> "doloremquealiquidrerum"
Faker::Internet.password(8) #=> "consecteturadasperiores"
Faker::Internet.domain_name #=> "effertz.info"
Faker::Internet.domain_word #=> "haleyziemann"
Faker::Internet.domain_suffix #=> "info"
Faker::Internet.ip_v4_address #=> "24.29.18.175"
Faker::Internet.ip_v6_address #=> "ac5f:d696:3807:1d72:2eb5:4e81:7d2b:e1df"
# Optional arguments: host=domain_name, path="/#{user_name}"
Faker::Internet.url #=> "http://thiel.com/chauncey_simonis"
# Optional arguments: words=nil, glue=nil
Faker::Internet.slug #=> "pariatur_laudantium"
Faker::Internet.slug('foo bar') #=> "foo.bar"
Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
Faker::Internet.url
Faker::Internet.slug
```
### Faker::Lorem
```crystal
Faker::Lorem.words
Faker::Lorem.words(4)
Faker::Lorem.words(4, true)
Faker::Lorem.characters
Faker::Lorem.characters(10)
Faker::Lorem.word #=> "repellendus"
Faker::Lorem.sentence
Faker::Lorem.sentence(3)
Faker::Lorem.sentence(3, true)
# Optional arguments: num=3, supplemental=false
Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]
Faker::Lorem.sentences
Faker::Lorem.sentences(1)
Faker::Lorem.sentences(1, true)
# Optional arguments: char_count=255
Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
Faker::Lorem.characters(10) #=> "ang9cbhoa8"
Faker::Lorem.paragraph
Faker::Lorem.paragraph(2)
Faker::Lorem.paragraph(2, true)
# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
# Optional arguments: sentence_count=3, supplemental=false
Faker::Lorem.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."]
Faker::Lorem.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."]
Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et ipsum."]
# Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente."
Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum."
Faker::Lorem.paragraph(2, true) #=> ""
# Optional arguments: paragraph_count=3, supplemental=false
Faker::Lorem.paragraphs #=> ""
Faker::Lorem.paragraphs(1) #=> ""
Faker::Lorem.paragraphs(1, true) #=> ""
Faker::Lorem.paragraphs
Faker::Lorem.paragraphs(1)
Faker::Lorem.paragraphs(1, true)
```
### Faker::Name
```crystal
Faker::Name.name
Faker::Name.first_name
Faker::Name.last_name
Faker::Name.prefix
Faker::Name.suffix
Faker::Name.title
Faker::Name.name #=> "Tyshawn Johns Sr."
Faker::Name.first_name #=> "Kaci"
Faker::Name.last_name #=> "Ernser"
Faker::Name.prefix #=> "Mr."
Faker::Name.suffix #=> "IV"
Faker::Name.title #=> "Legacy Creative Director"
```
### Faker::Number
```crystal
Faker::Number.number(10)
Faker::Number.decimal(2)
Faker::Number.decimal(2, 3)
Faker::Number.digit
# Required parameter: digits
Faker::Number.number(10) #=> "1968353479"
# Required parameter: l_digits
Faker::Number.decimal(2) #=> "11.88"
Faker::Number.decimal(2, 3) #=> "18.843"
Faker::Number.digit #=> "1"
```
### Faker::PhoneNumber
```crystal
Faker::PhoneNumber.phone_number
Faker::PhoneNumber.phone_number #=> "397.693.1309"
```

View File

@ -98,3 +98,9 @@ puts Faker::Number.digit
puts "\n\t### Faker::PhoneNumber\n\n"
puts Faker::PhoneNumber.phone_number
puts "\n\t### Faker::Business\n\n"
p Faker::Business.credit_card_number
p Faker::Business.credit_card_expiry_date
p Faker::Business.credit_card_type

144
src/data.cr Normal file

File diff suppressed because one or more lines are too long

View File

@ -11,12 +11,7 @@ module Faker
{% end %}
def self.city
[
"%s %s%s" % [city_prefix, Name.first_name, city_suffix],
"%s %s" % [city_prefix, Name.first_name],
"%s%s" % [Name.first_name, city_suffix],
"%s%s" % [Name.last_name, city_suffix],
].sample
Faker.fetch(Data["address"]["city"])
end
def self.street_name

File diff suppressed because one or more lines are too long

25
src/faker/finance.cr Normal file
View File

@ -0,0 +1,25 @@
module Faker
class Finance
CREDIT_CARD_TYPES = (Data["credit_card"] as Hash).keys
def self.credit_card(types = [] of Array(String) : Array)
types = CREDIT_CARD_TYPES if types.empty?
type = types.sample
template = Faker.numerify(Faker.fetch(Data["credit_card"]["#{type}"]))
# calculate the luhn checksum digit
multiplier = 1
luhn_sum = template.gsub(/[^0-9]/, "").split("").reverse.map(&.to_i).inject(0) do |sum, digit|
multiplier = (multiplier == 2 ? 1 : 2)
sum + (digit * multiplier).to_s.split("").map(&.to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
end
# the sum plus whatever the last digit is must be a multiple of 10. So, the
# last digit must be 10 - the last digit of the sum.
luhn_digit = (10 - (luhn_sum % 10)) % 10
template = template.gsub "L", luhn_digit.to_s
template
end
end
end