forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b834eec
commit 63c8ff9
Showing
7 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |