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

stympy master #8

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8d8e009
[Fix issue #300] Generate random hex color value
Jan 27, 2015
68cdbc9
Add support for generating RGB values
Jan 28, 2015
bcbabc4
Add support for HSL colors
Jan 28, 2015
f4d975c
Support alpha channel and HSLA colors
Jan 28, 2015
8dcd9a5
Fix build
Jan 28, 2015
a144a82
Replace rand range
Jan 28, 2015
9705438
Fix bugs
Jan 28, 2015
3c45da1
Canadian Postcodes also can not start with DFIOQ or U
malmckay Feb 26, 2015
ccb291b
Fix typo
littleforest Mar 6, 2015
fd47dce
Added Swedish organisation number generator.
emidander Mar 10, 2015
e88c2ec
Adding name Ozzie to list of english first names
OAGr Mar 13, 2015
c64ab97
Add image sets option for avatar
h4r1sh Mar 25, 2015
d288d45
Add image sets option for avatar
h4r1sh Mar 25, 2015
d00ce11
Merge branch 'master' of https://github.com/h4r1sh/faker
h4r1sh Mar 25, 2015
41de93e
Remove `warning: ambiguous first argument; put parentheses or a space…
Mar 30, 2015
5bfbc52
:memo: Add country code documentation
philipgiuliani Apr 9, 2015
7b952e7
Faker::Business.credit_card_expiry_date gives random date based on ::…
jdbalistreri Apr 10, 2015
3a4049a
fixed for compatibility with ruby 1.9.2
jdbalistreri Apr 16, 2015
0216e79
Update README
guilhermesimoes Apr 9, 2015
d6a3b92
work in progress comit
morozgrafix May 12, 2015
84de600
Added Slack Emoji faker, docs and corresponding tests
May 13, 2015
b01b1db
better description in README
May 13, 2015
45b933f
fixed typo in README
May 14, 2015
1eb7c33
Add material and buzzword methods, increase some word banks
May 22, 2015
5bddb64
Added :pride: emoji
May 26, 2015
4713ce0
better slack_emoji tests
May 26, 2015
89d1ddf
Merge pull request #358 from dmccown/fix_mispeled_word
stympy May 30, 2015
889ba68
Merge pull request #353 from DrewMartin/master
stympy May 30, 2015
0144fae
Merge pull request #351 from morozgrafix/slack_emoji
stympy May 30, 2015
8a4f572
Merge pull request #350 from backus/master
stympy May 30, 2015
6a07872
Merge pull request #349 from Roemerb/master
stympy May 30, 2015
256731e
Merge pull request #345 from jdbalistreri/master
stympy May 30, 2015
70de77e
Merge pull request #344 from guilhermesimoes/patch-1
stympy May 30, 2015
fcfd297
Merge pull request #343 from philipgiuliani/patch-1
stympy May 30, 2015
88a4d18
Merge pull request #336 from takiy33/fix_ambiguout_first_argument_war…
stympy May 30, 2015
bfde7eb
Merge pull request #333 from h4r1sh/master
stympy May 30, 2015
68716ea
Merge pull request #332 from OAGr/patch-1
stympy May 30, 2015
f1823a1
Merge pull request #331 from emidander/master
stympy May 30, 2015
627cbb9
Merge pull request #329 from mobilecommons/canadian_postcodes
stympy May 30, 2015
ee1e600
Merge pull request #327 from littleforest/typo
stympy May 30, 2015
0521db8
Merge pull request #310 from kkirsche/generateRandomColor
stympy May 30, 2015
fed0079
Removed rubyforge_project option from .gemspec
May 31, 2015
4cbb492
Merge pull request #360 from takiy33/fix_gemspec
stympy May 31, 2015
9be9394
documentation updated for Lorem.paragraph and Lorem.paragraphs
manoj2411 May 31, 2015
152d7b6
Merge pull request #361 from manoj2411/master
stympy Jun 1, 2015
be5a12b
Test against Ruby 2.2.2
Jun 4, 2015
7a4e2a0
Merge pull request #362 from takiy33/travis
stympy Jun 4, 2015
87edfce
Remove extra space from hacker.ingverb
justjake Jun 8, 2015
dee7d55
Merge pull request #363 from justjake/patch-1
stympy Jun 9, 2015
ac8f89d
Test for ruby head
michaelachrisco Jun 11, 2015
73964d7
Merge pull request #364 from michaelachrisco/patch-1
stympy Jun 11, 2015
4e0ec9b
Add domain suffixes to en-US.yml
Jun 15, 2015
ac3853e
Add domain suffixes to en.yml
Jun 15, 2015
c9a617f
Merge pull request #365 from salexzee/master
stympy Jun 18, 2015
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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.2.2
- ruby-head
script: bundle exec rake test
matrix:
allow_failures:
- rvm: ruby-head
58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ Faker::Address.city_suffix #=> "fort"

Faker::Address.city_prefix #=> "Lake"

Faker::Address.state_abbr #=> "AP"

Faker::Address.state #=> "California"

Faker::Address.state_abbr #=> "AP"

Faker::Address.country #=> "French Guiana"

Faker::Address.country_code #=> "IT"

Faker::Address.latitude #=> "-58.17256227443719"

Faker::Address.longitude #=> "-156.65548382095133"
Expand Down Expand Up @@ -246,14 +248,14 @@ Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et
# 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) #=> ""
Faker::Lorem.paragraph(2, false, 4) #=> ""
Faker::Lorem.paragraph(2, true, 4) #=> ""
Faker::Lorem.paragraph(2, true) #=> "Cedo vero adipisci. Theatrum crustulum coaegresco tonsor crastinus stabilis. Aliqua crur consequatur amor una tolero sum."
Faker::Lorem.paragraph(2, false, 4) #=> "Neque aut et nemo aut incidunt voluptates. Dolore cum est sint est. Vitae assumenda porro odio dolores fugiat. Est voluptatum quia rerum."
Faker::Lorem.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum."

# Optional arguments: paragraph_count=3, supplemental=false
Faker::Lorem.paragraphs #=> ""
Faker::Lorem.paragraphs(1) #=> ""
Faker::Lorem.paragraphs(1, true) #=> ""
Faker::Lorem.paragraphs #=> ["Dolores quis quia ad quo voluptates. Maxime delectus totam numquam. Necessitatibus vel atque qui dolore.", "Id neque nemo. Dolores iusto facere est ad. Accusamus ipsa dolor ut.", "Et officiis ut hic. Sunt asperiores minus distinctio debitis ipsa dolor. Minima eos deleniti."]
Faker::Lorem.paragraphs(1) #=> ["Labore voluptas sequi. Ratione nulla eaque quia molestiae fugit. At quam laboriosam aut ut dignissimos."]
Faker::Lorem.paragraphs(1, true) #=> ["Depulso animi cunctatio amicitia adficio. Vester viduo qui despirmatio voluptas. Validus laudantium adopto ut agnitio venustas. Aer arcus odio esse."]

```

Expand Down Expand Up @@ -351,9 +353,11 @@ Faker::PhoneNumber.extension #=> "3764"

```ruby
# Random date between dates
Faker::Time.between(2.days.ago, Time.now) #=> "2014-09-18 12:30:59 -0700"
Faker::Time.between(DateTime.now - 1, DateTime.now) #=> "2014-09-18 12:30:59 -0700"

# Random date between dates (within specified part of the day)
# You can install the active_support gem to facilitate time manipulation like 45.minutes + 2.hours
require "as-duration"
Faker::Time.between(2.days.ago, Time.now, :all) #=> "2014-09-19 07:03:30 -0700"
Faker::Time.between(2.days.ago, Time.now, :day) #=> "2014-09-18 16:28:13 -0700"
Faker::Time.between(2.days.ago, Time.now, :night) #=> "2014-09-20 19:39:38 -0700"
Expand Down Expand Up @@ -407,6 +411,40 @@ Faker::App.author #=> "Daphne Swift"

```

###Faker::SlackEmoji
-----------------

```ruby

# Random Slack Emoji from people category
Faker::SlackEmoji.people #=> ":sleepy:"

# Random Slack Emoji from nature category
Faker::SlackEmoji.nature #=> ":chestnut:"

# Random Slack Emoji from food and drink category
Faker::SlackEmoji.food_and_drink #=> ":tangerine:"

# Random Slack Emoji from celebration category
Faker::SlackEmoji.celebration #=> ":ribbon:"

# Random Slack Emoji from activity category
Faker::SlackEmoji.activity #=> ":performing_arts:"

# Random Slack Emoji from travel and places category
Faker::SlackEmoji.travel_and_places #=> ":truck:"

# Random Slack Emoji from objects & symbols category
Faker::SlackEmoji.objects_and_symbols #=> ":alarm_clock:"

# Random Slack Emoji from custom category
Faker::SlackEmoji.custom #=> ":suspect:"

# Random Slack Emoji from any category
Faker::SlackEmoji.emoji #=> ":last_quarter_moon:"

```

Customization
------------
Since you may want to make addresses and other types of data look different
Expand All @@ -425,7 +463,7 @@ and you can then override or add elements to suit
en-au-ocker:
faker:
name:
# Exiting faker field, new data
# Existing faker field, new data
first_name: [Charlotte, Ava, Chloe, Emily]

# New faker fields
Expand Down
2 changes: 0 additions & 2 deletions faker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Gem::Specification.new do |s|
s.description = %q{Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.}
s.license = 'MIT'

s.rubyforge_project = "faker"

s.add_dependency('i18n', '~> 0.5')

s.files = `git ls-files -- lib/*`.split("\n") + %w(History.txt License.txt README.md)
Expand Down
2 changes: 2 additions & 0 deletions lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def rand_in_range(from, to)

require 'faker/address'
require 'faker/code'
require 'faker/color'
require 'faker/company'
require 'faker/finance'
require 'faker/internet'
Expand All @@ -177,6 +178,7 @@ def rand_in_range(from, to)
require 'faker/number'
require 'faker/hacker'
require 'faker/app'
require 'faker/slack_emoji'

require 'extensions/array'
require 'extensions/symbol'
4 changes: 2 additions & 2 deletions lib/faker/avatar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class Avatar < Base
class << self
SUPPORTED_FORMATS = %w(png jpg bmp)

def image(slug = nil, size = '300x300', format = 'png')
def image(slug = nil, size = '300x300', format = 'png', set = 'set1')
raise ArgumentError, "Size should be specified in format 300x300" unless size.match(/^[0-9]+x[0-9]+$/)
raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
slug ||= Faker::Lorem.words.join
"http://robohash.org/#{slug}.#{format}?size=#{size}"
"http://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/faker/business.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def credit_card_number
end

def credit_card_expiry_date
::Date.parse(fetch('business.credit_card_expiry_dates'))
::Date.today + (365 * (rand(4) + 1))
end

def credit_card_type
Expand Down
49 changes: 49 additions & 0 deletions lib/faker/color.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Faker
class Color < Base
class << self
def hex_color
@hex_color = "#%06x" % (rand * 0xffffff)
end

def single_rgb_color
@single_rgb_color = (0..255).to_a.sample
@single_rgb_color
end

def rgb_color
@rgb_colors = []
3.times do
@rgb_colors.push single_rgb_color
end
@rgb_colors
end

def single_hsl_color
@single_hsla_color = Faker::Base::rand_in_range(0.0, 360.00).round(2)
@single_hsla_color
end

def alpha_channel
@alpha_channel = rand
@alpha_channel
end

def hsl_color
@hsl_colors = []
3.times do
@hsl_colors.push single_hsl_color
end
@hsl_colors
end

def hsla_color
@hsla_colors = []
3.times do
@hsla_colors.push single_hsl_color
end
@hsla_colors.push alpha_channel
@hsla_colors
end
end
end
end
6 changes: 5 additions & 1 deletion lib/faker/commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ def product_name
fetch('commerce.product_name.adjective') + ' ' + fetch('commerce.product_name.material') + ' ' + fetch('commerce.product_name.product')
end

def material
fetch('commerce.product_name.material')
end

def price
random = Random.new
(random.rand(0..100.0) * 100).floor/100.0
end
end

private

Expand Down
40 changes: 39 additions & 1 deletion lib/faker/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def catch_phrase
translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
end

def buzzword
translate('faker.company.buzzwords').flatten.sample
end

# When a straight answer won't do, BS to the rescue!
def bs
translate('faker.company.bs').collect {|list| list.sample }.join(' ')
Expand All @@ -34,7 +38,41 @@ def logo
rand_num = Random.rand(13) + 1
"http://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
end
end

def swedish_organisation_number
base = ('%09d' % rand(10 ** 9))
base + luhn_algorithm(base).to_s
end

private

def luhn_algorithm(number)
multiplications = []

number.split(//).each_with_index do |digit, i|
if i % 2 == 0
multiplications << digit.to_i * 2
else
multiplications << digit.to_i
end
end

sum = 0

multiplications.each do |num|
num.to_s.each_byte do |character|
sum += character.chr.to_i
end
end

if sum % 10 == 0
control_digit = 0
else
control_digit = (sum / 10 + 1) * 10 - sum
end

control_digit
end
end
end
end
43 changes: 43 additions & 0 deletions lib/faker/slack_emoji.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Faker
class SlackEmoji < Base
class << self

def people
fetch('slack_emoji.people')
end

def nature
fetch('slack_emoji.nature')
end

def food_and_drink
fetch('slack_emoji.food_and_drink')
end

def celebration
fetch('slack_emoji.celebration')
end

def activity
fetch('slack_emoji.activity')
end

def travel_and_places
fetch('slack_emoji.travel_and_places')
end

def objects_and_symbols
fetch('slack_emoji.objects_and_symbols')
end

def custom
fetch('slack_emoji.custom')
end

def emoji
parse('slack_emoji.emoji')
end

end
end
end
2 changes: 1 addition & 1 deletion lib/locales/en-CA.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
en-CA:
faker:
address:
postcode: /[A-VX-Y][0-9][A-CEJ-NPR-TV-Z] ?[0-9][A-CEJ-NPR-TV-Z][0-9]/
postcode: /[A-CEJ-NPR-TVXY][0-9][A-CEJ-NPR-TV-Z] ?[0-9][A-CEJ-NPR-TV-Z][0-9]/
state: [Alberta, British Columbia, Manitoba, New Brunswick, Newfoundland and Labrador, Nova Scotia, Northwest Territories, Nunavut, Ontario, Prince Edward Island, Quebec, Saskatchewan, Yukon]
state_abbr: ["AB", "BC", "MB", "NB", "NL", "NS", "NU", "NT", "ON", "PE", "QC", "SK", "YT"]
default_country: [Canada]
Expand Down
2 changes: 1 addition & 1 deletion lib/locales/en-US.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
en-US:
faker:
internet:
domain_suffix: [com, us, biz, info, name, net, org]
domain_suffix: [com, us, biz, info, name, net, org, io, co]
address:
default_country: [United States, United States of America, USA]
postcode_by_state:
Expand Down
35 changes: 27 additions & 8 deletions lib/locales/en.yml

Large diffs are not rendered by default.

Loading