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

Add Faker::Games::SonicTheHedgehog #1422

Merged
merged 4 commits into from
Oct 19, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [PR #1329](https://github.com/stympy/faker/pull/1329) Update docs on behavior of price [@softwaregravy](https://github.com/softwaregravy)

### Feature Request
- [PR #1422](https://github.com/stympy/faker/pull/1422) Add Faker::Games::SonicTheHedgehog [@boardfish](https://github.com/boardfish)
- [PR #1413](https://github.com/stympy/faker/pull/1413) Add Faker::Games::Heroes [@tangens](https://github.com/tangens)
- [PR #1409](https://github.com/stympy/faker/pull/1409) Add DC Comics titles [@matheusteixeira](https://github.com/matheusteixeira)
- [PR #1400](https://github.com/stympy/faker/pull/1400) Add Faker::Movies::Ghostbusters [@eddorre](https://github.com/eddorre)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Contents
- [Faker::Games::HalfLife](doc/half_life.md)
- [Faker::Games::Heroes](doc/heroes.md)
- [Faker::Games::HeroesOfTheStorm](doc/heroes_of_the_storm.md)
- [Faker::Games::SonicTheHedgehog](doc/sonic_the_hedgehog.md)
- [Faker::Gender](doc/gender.md)
- [Faker::GreekPhilosophers](doc/greek_philosophers.md)
- [Faker::Hacker](doc/hacker.md)
Expand Down
29 changes: 22 additions & 7 deletions doc/placeholdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,32 @@
```ruby
Faker::Placeholdit.image #=> "http://placehold.it/300x300.png/000"

Faker::Placeholdit.image("50x50") #=> "http://placehold.it/50x50.png/000"
Faker::Placeholdit.image('50x50') #=> "http://placehold.it/50x50.png/000"

Faker::Placeholdit.image("50x50", 'jpg') #=> "http://placehold.it/50x50.jpg/000"
Faker::Placeholdit.image('50x50', 'jpg') #=> "http://placehold.it/50x50.jpg/000"

Faker::Placeholdit.image("50x50", 'gif', 'ffffff') #=> "http://placehold.it/50x50.gif/ffffff"
Faker::Placeholdit.image('50x50', 'gif', 'ffffff') #=> "http://placehold.it/50x50.gif/ffffff"

Faker::Placeholdit.image("50x50", 'jpeg', :random) #=> "http://placehold.it/50x50.jpeg/39eba7"
Faker::Placeholdit.image('50x50', 'jpeg', :random) #=> "http://placehold.it/50x50.jpeg/39eba7"

Faker::Placeholdit.image("50x50", 'jpeg', 'ffffff', '000') #=> "http://placehold.it/50x50.jpeg/ffffff/000"
Faker::Placeholdit.image('50x50', 'jpeg', 'ffffff', '000') #=> "http://placehold.it/50x50.jpeg/ffffff/000"

Faker::Placeholdit.image("50x50", 'jpeg', :random, :random) #=> "http://placehold.it/50x50.jpeg/d39e44/888ba7"
Faker::Placeholdit.image('50x50', 'jpeg', :random, :random) #=> "http://placehold.it/50x50.jpeg/d39e44/888ba7"

Faker::Placeholdit.image("50x50", 'jpg', 'ffffff', '000', 'Some Custom Text') #=> "http://placehold.it/50x50.jpg/ffffff/000?text='Some Custom Text'"
Faker::Placeholdit.image('50x50', 'jpg', 'ffffff', '000', 'Some Custom Text') #=> "http://placehold.it/50x50.jpg/ffffff/000?text='Some Custom Text'"
```

## Tips

If you want to have this file downloaded, like in your tests, you could use this following piece of code:

```ruby
def image_file(size = '300x300', format = 'png', background_color = nil, text_color = nil, text = nil)
file = Tempfile.new("faker_placeholdit")
file.binmode
file << Net::HTTP.get(URI(Faker::Placeholdit.image(size, format, background_color, text_color, text)))
file.close

::File.new(file.path)
end
```
9 changes: 9 additions & 0 deletions doc/sonic_the_hedgehog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Faker::Games::SonicTheHedgehog

```ruby
# Any character from the games
Faker::Games::SonicTheHedgehog.character #=> "Sonic the Hedgehog"

# Any zone from the series
Faker::Games::SonicTheHedgehog.zone #=> "The Legend of Zelda Zone"
```
5 changes: 4 additions & 1 deletion doc/vehicle.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ Faker::Vehicle.mileage(50_000) #=> 81557
Faker::Vehicle.mileage(50_000, 250_000) #=> 117503
Faker::Vehicle.kilometrage #=> 35378

# Random vehicle license plate
# Random vehicle license plate (USA by default)
Faker::Vehicle.license_plate #=> "DEP-2483"
Faker::Vehicle.license_plate('FL') #=> "977 UNU"

# Random vehicle license plate for Singapore (if locale is set)
Faker::Vehicle.singapore_license_plate #=> "SLV1854M"
```
17 changes: 17 additions & 0 deletions lib/faker/games/sonic_the_hedgehog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Faker
module Games
class SonicTheHedgehog < Base
class << self
def character
fetch('games.sonic_the_hedgehog.character')
end

def zone
fetch('games.sonic_the_hedgehog.zone')
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/faker/placeholdit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def image(size = '300x300', format = 'png', background_color = nil, text_color =

raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/

image_url = "https://placehold.it/#{size}.#{format}"
image_url += "/#{background_color}" if background_color
Expand Down
19 changes: 19 additions & 0 deletions lib/faker/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Vehicle < Base
VIN_MAP = '0123456789X'
VIN_WEIGHTS = '8765432X098765432'
VIN_REGEX = /^[A-Z0-9]{3}[A-Z0-9]{5}[A-Z0-9]{1}[A-Z0-9]{1}[A-Z0-0]{1}[A-Z0-9]{1}\d{5}$/
SG_CHECKSUM_WEIGHTS = [3, 14, 2, 12, 2, 11, 1].freeze
SG_CHECKSUM_CHARS = 'AYUSPLJGDBZXTRMKHEC'

class << self
def vin
Expand Down Expand Up @@ -96,6 +98,12 @@ def license_plate(state_abreviation = '')
regexify(bothify(fetch(key)))
end

def singapore_license_plate
key = 'vehicle.license_plate'
plate_number = regexify(bothify(fetch(key)))
"#{plate_number}#{singapore_checksum(plate_number)}"
end

private

def first_eight(number)
Expand Down Expand Up @@ -125,6 +133,17 @@ def vin_char_to_number(char)

VIN_MAP[index]
end

def singapore_checksum(plate_number)
padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').split('')
padded_digits = format('%04d', plate_number[/\d+/]).split('').map(&:to_i)
sum = [*padded_alphabets, *padded_digits].each_with_index.reduce(0) do |memo, (char, i)|
value = char.is_a?(Integer) ? char : char.ord - 64
memo + (SG_CHECKSUM_WEIGHTS[i] * value)
end

SG_CHECKSUM_CHARS.split('')[sum % 19]
end
end
end
end
2 changes: 2 additions & 0 deletions lib/locales/en-SG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ en-SG:
default_country: [Singapore]
phone_number:
formats: ['+65 6### ####', '+65 9### ####', '+65 8### ####']
vehicle:
license_plate: 'S??####'
Loading