Skip to content

Commit

Permalink
Faker::Compass (faker-ruby#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlwilbur authored and stympy committed Mar 18, 2017
1 parent b834eec commit 63c8ff9
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Contents
- [Faker::Color](doc/color.md)
- [Faker::Commerce](doc/commerce.md)
- [Faker::Company](doc/company.md)
- [Faker::Compass](doc/compass.md)
- [Faker::Crypto](doc/crypto.md)
- [Faker::Date](doc/date.md)
- [Faker::Demographic](doc/demographic.md)
Expand Down Expand Up @@ -110,7 +111,7 @@ that have been returned, for example between tests.
Faker::Name.unique.clear # Clears used values for Faker::Name
Faker::UniqueGenerator.clear # Clears used values for all generators
```
It is also possible to add a random number to the end of faker data to increase the
It is also possible to add a random number to the end of faker data to increase the
likelihood of unique data being generated. For example:

```ruby
Expand Down
24 changes: 24 additions & 0 deletions doc/compass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Faker::Compass

```ruby
# A random direction
Faker::Compass.direction #=> "southeast"
Faker::Compass.cardinal #=> "north"
Faker::Compass.ordinal #=> "northwest"
Faker::Compass.half_wind #=> "north-northwest"
Faker::Compass.quarter_wind #=> "north by west"

# Random abbreviation
Faker::Compass.abbreviation #=> "NEbN"
Faker::Compass.cardinal_abbreviation #=> "N"
Faker::Compass.ordinal_abbreviation #=> "SW"
Faker::Compass.half_wind_abbreviation #=> "NNE"
Faker::Compass.quarter_wind_abbreviation #=> "SWbS"

# Random azimuth
Faker::Compass.azimuth #=> "168.75"
Faker::Compass.cardinal_azimuth #=> "90"
Faker::Compass.ordinal_azimuth #=> "135"
Faker::Compass.half_wind_azimuth #=> "292.5"
Faker::Compass.quarter_wind_azimuth #=> "56.25"
```
1 change: 1 addition & 0 deletions lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def rand(max = nil)
require 'faker/code'
require 'faker/color'
require 'faker/company'
require 'faker/compass'
require 'faker/university'
require 'faker/finance'
require 'faker/internet'
Expand Down
65 changes: 65 additions & 0 deletions lib/faker/compass.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module Faker
class Compass < Base
class << self
def cardinal
fetch('compass.cardinal.word')
end

def ordinal
fetch('compass.ordinal.word')
end

def half_wind
fetch('compass.half-wind.word')
end

def quarter_wind
fetch('compass.quarter-wind.word')
end

def direction
parse('compass.direction')
end

def abbreviation
parse('compass.abbreviation')
end

def azimuth
parse('compass.azimuth')
end

def cardinal_abbreviation
fetch('compass.cardinal.abbreviation')
end

def ordinal_abbreviation
fetch('compass.ordinal.abbreviation')
end

def half_wind_abbreviation
fetch('compass.half-wind.abbreviation')
end

def quarter_wind_abbreviation
fetch('compass.quarter-wind.abbreviation')
end

def cardinal_azimuth
fetch('compass.cardinal.azimuth')
end

def ordinal_azimuth
fetch('compass.ordinal.azimuth')
end

def half_wind_azimuth
fetch('compass.half-wind.azimuth')
end

def quarter_wind_azimuth
fetch('compass.quarter-wind.azimuth')
end
end
end
end
33 changes: 33 additions & 0 deletions lib/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ de:
- "#{Name.last_name}-#{Name.last_name}"
- "#{Name.last_name}, #{Name.last_name} und #{Name.last_name}"

compass:
cardinal:
word: ['Norden', 'Osten', 'Süden', 'Westen']
abbreviation: ['N', 'E', 'S', 'W']
azimuth: ['0', '90', '180', '270']
ordinal:
word: ['Nordosten', 'Südosten', 'Südwesten', 'Nordwesten']
abbreviation: ['NO', 'SO', 'SW', 'NW']
azimuth: ['45', '135', '225', '315']
half-wind:
word: ['Nord-Nordost', 'Ost-Nordost', 'Ost-Südost', 'Süd-Südost', 'Süd-Südwest', 'West-Südwest', 'West-Nordwest', 'Nord-Nordwest']
abbreviation: ['NNO', 'ONO', 'OSO', 'SSO', 'SSW', 'WSW', 'WNW', 'NNW']
azimuth: ['22.5', '67.5', '112.5', '157.5', '202.5', '247.5', '292.5', '337.5']
quarter-wind:
word: ['Norden von Osten', 'Nordosten von Norden', 'Nordosten von Osten', 'Osten von Norden', 'Osten von Süden', 'Südosten von Osten', 'Südosten von Süden', 'Süden von Osten', 'Süden von Westen', 'Südwesten von Süden', 'Südwesten von Westen', 'Westen von Süden', 'Westen von Norden', 'Nordwesten von Westen', 'Nordwesten von Norden', 'Norden von Westen']
abbreviation: ['NvO', 'NOvN', 'NOvO', 'OvN', 'OvS', 'SOvO', 'SOvS', 'SvO', 'SvW', 'SWvS', 'SWvW', 'WvS', 'WvN', 'NWvW', 'NWvN', 'NvW']
azimuth: ['11.25', '33.75', '56.25', '78.75', '101.25', '123.75', '146.25', '168.75', '191.25', '213.75', '236.25', '258.75', '281.25', '303.75', '326.25', '348.75']
direction:
- "#{cardinal}"
- "#{ordinal}"
- "#{half_wind}"
- "#{quarter_wind}"
abbreviation:
- "#{cardinal_abbreviation}"
- "#{ordinal_abbreviation}"
- "#{half_wind_abbreviation}"
- "#{quarter_wind_abbreviation}"
azimuth:
- "#{cardinal_azimuth}"
- "#{ordinal_azimuth}"
- "#{half_wind_azimuth}"
- "#{quarter_wind_azimuth}"

internet:
free_email: [gmail.com, yahoo.com, hotmail.com, gmx.de, web.de, mail.de, freenet.de]
domain_suffix: [com, info, name, net, org, de, ch]
Expand Down
33 changes: 33 additions & 0 deletions lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ en:
industry: ["Defense & Space", "Computer Hardware", "Computer Software", "Computer Networking", "Internet", "Semiconductors", "Telecommunications", "Law Practice", "Legal Services", "Management Consulting", "Biotechnology", "Medical Practice", "Hospital & Health Care", "Pharmaceuticals", "Veterinary", "Medical Devices", "Cosmetics", "Apparel & Fashion", "Sporting Goods", "Tobacco", "Supermarkets", "Food Production", "Consumer Electronics", "Consumer Goods", "Furniture", "Retail", "Entertainment", "Gambling & Casinos", "Leisure, Travel & Tourism", "Hospitality", "Restaurants", "Sports", "Food & Beverages", "Motion Pictures and Film", "Broadcast Media", "Museums and Institutions", "Fine Art", "Performing Arts", "Recreational Facilities and Services", "Banking", "Insurance", "Financial Services", "Real Estate", "Investment Banking", "Investment Management", "Accounting", "Construction", "Building Materials", "Architecture & Planning", "Civil Engineering", "Aviation & Aerospace", "Automotive", "Chemicals", "Machinery", "Mining & Metals", "Oil & Energy", "Shipbuilding", "Utilities", "Textiles", "Paper & Forest Products", "Railroad Manufacture", "Farming", "Ranching", "Dairy", "Fishery", "Primary / Secondary Education", "Higher Education", "Education Management", "Research", "Military", "Legislative Office", "Judiciary", "International Affairs", "Government Administration", "Executive Office", "Law Enforcement", "Public Safety", "Public Policy", "Marketing and Advertising", "Newspapers", "Publishing", "Printing", "Information Services", "Libraries", "Environmental Services", "Package / Freight Delivery", "Individual & Family Services", "Religious Institutions", "Civic & Social Organization", "Consumer Services", "Transportationg / Trucking / Railroad", "Warehousing", "Airlines / Aviation", "Maritime", "Information Technology and Services", "Market Research", "Public Relations and Communications", "Design", "Nonprofit Organization Management", "Fund-Raising", "Program Development", "Writing and Editing", "Staffing and Recruiting", "Professional Training & Coaching", "Venture Capital & Private Equity", "Political Organization", "Translation and Localization", "Computer Games", "Events Services", "Arts and Crafts", "Electrical / Electronic Manufacturing", "Online Media", "Nanotechnology", "Music", "Logistics and Supply Chain", "Plastics", "Computer & Network Security", "Wireless", "Alternative Dispute Resolution", "Security and Investigations", "Facilities Services", "Outsourcing / Offshoring", "Health, Wellness and Fitness", "Alternative Medicine", "Media Production", "Animation", "Commercial Real Estate", "Capital Markets", "Think Tanks", "Philanthropy", "E-Learning", "Wholesale", "Import and Export", "Mechanical or Industrial Engineering", "Photography", "Human Resources", "Business Supplies and Equipment", "Mental Health Care", "Graphic Design", "International Trade and Development", "Wine and Spirits", "Luxury Goods & Jewelry", "Renewables & Environment", "Glass, Ceramics & Concrete", "Packaging and Containers", "Industrial Automation", "Government Relations"]
profession: ["teacher", "actor", "musician", "philosopher", "writer", "doctor", "accountant", "agriculturist", "architect", "economist", "engineer", "interpreter", "attorney at law", "advocate", "librarian", "statistician", "human resources", "firefighter", "judge", "police officer", "astronomer", "biologist", "chemist", "physicist", "programmer", "web developer", "designer"]

compass:
cardinal:
word: ['north', 'east', 'south', 'west']
abbreviation: ['N', 'E', 'S', 'W']
azimuth: ['0', '90', '180', '270']
ordinal:
word: ['northeast', 'southeast', 'southwest', 'northwest']
abbreviation: ['NE', 'SE', 'SW', 'NW']
azimuth: ['45', '135', '225', '315']
half-wind:
word: ['north-northeast', 'east-northeast', 'east-southeast', 'south-southeast', 'south-southwest', 'west-southwest', 'west-northwest', 'north-northwest']
abbreviation: ['NNE', 'ENE', 'ESE', 'SSE', 'SSW', 'WSW', 'WNW', 'NNW']
azimuth: ['22.5', '67.5', '112.5', '157.5', '202.5', '247.5', '292.5', '337.5']
quarter-wind:
word: ['north by east', 'northeast by north', 'northeast by east', 'east by north', 'east by south', 'southeast by east', 'southeast by south', 'south by east', 'south by west', 'southwest by south', 'southwest by west', 'west by south', 'west by north', 'northwest by west', 'northwest by north', 'north by west']
abbreviation: ['NbE', 'NEbN', 'NEbE', 'EbN', 'EbS', 'SEbE', 'SEbS', 'SbE', 'SbW', 'SWbS', 'SWbW', 'WbS', 'WbN', 'NWbW', 'NWbN', 'NbW']
azimuth: ['11.25', '33.75', '56.25', '78.75', '101.25', '123.75', '146.25', '168.75', '191.25', '213.75', '236.25', '258.75', '281.25', '303.75', '326.25', '348.75']
direction:
- "#{cardinal}"
- "#{ordinal}"
- "#{half_wind}"
- "#{quarter_wind}"
abbreviation:
- "#{cardinal_abbreviation}"
- "#{ordinal_abbreviation}"
- "#{half_wind_abbreviation}"
- "#{quarter_wind_abbreviation}"
azimuth:
- "#{cardinal_azimuth}"
- "#{ordinal_azimuth}"
- "#{half_wind_azimuth}"
- "#{quarter_wind_azimuth}"

university:
prefix: [The, Northern, North, Western, West, Southern, South, Eastern, East]
suffix: [University, Institute, College, Academy]
Expand Down
40 changes: 40 additions & 0 deletions test/test_faker_compass.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')

class TestFakerCompass < Test::Unit::TestCase
def setup
@tester = Faker::Compass
@word_pattern = /\w+/
@multiword_pattern = /^\w+ by \w+$/
@combined_pattern = /^(?:\w+|\w+ by \w+)$/
@number_pattern = /^[\d]+(?:.\d\d?)?$/
@letter_pattern = /^[NEWS]?[NEWS](?:b?[NEWS])?$/
end

def test_cardinal
assert @tester.cardinal.match(@word_pattern)
end

def test_ordinal
assert @tester.ordinal.match(@word_pattern)
end

def test_half_wind
assert @tester.half_wind.match(@word_pattern)
end

def test_quarter_wind
assert @tester.quarter_wind.match(@multiword_pattern)
end

def test_direction
assert @tester.direction.match(@combined_pattern)
end

def test_abbreviation
assert @tester.abbreviation.match(@letter_pattern)
end

def test_azimuth
assert @tester.azimuth.match(@number_pattern)
end
end

0 comments on commit 63c8ff9

Please sign in to comment.