Permalink
Browse files

Merge branch 'master' of https://github.com/stympy/faker

* 'master' of https://github.com/stympy/faker:
  MacGyver is only the best last name!
  Changed homepage location to github
  1.0.1 Release
  Make the parser use the locale fallback
  Add safe_email method.
  • Loading branch information...
2 parents 6f3d264 + 71c7a4c commit 40d640c0ce54453d25d97a8de1ba51e579ebd8f5 @kytrinyx kytrinyx committed Dec 26, 2011
View
@@ -1,3 +1,9 @@
+== 1.0.1 2011-09-27
+* 1 minor enhancement
+ * Added safe_email method to get someaddress@example.com [Kazimierz Kiełkowicz]
+* 1 bug fix:
+ * Use the locale fallback properly when parsing string formats
+
== 1.0.0 2011-09-08
* 2 major enhancements
* Moved all formats to locale files
View
@@ -47,7 +47,18 @@ def fetch(key)
# into method calls that can be used to generate a
# formatted translation: e.g., "#{first_name} #{last_name}".
def parse(key)
- fetch(key).scan(/#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|kls, meth, etc| (kls ? Faker.const_get(kls.chop) : self).send(meth) + etc.to_s }.join
+ fetch(key).scan(/#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|kls, meth, etc|
+ # If the token had a class Prefix (e.g., Name.first_name)
+ # grab the constant, otherwise use self
+ cls = kls ? Faker.const_get(kls.chop) : self
+
+ # If the class has the method, call it, otherwise
+ # fetch the transation (i.e., faker.name.first_name)
+ text = cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}")
+
+ # And tack on spaces, commas, etc. left over in the string
+ text += etc.to_s
+ }.join
end
# Call I18n.translate with our configured locale if no
View
@@ -10,6 +10,10 @@ def free_email(name = nil)
[ user_name(name), fetch('internet.free_email') ].join('@')
end
+ def safe_email(name = nil)
+ [user_name(name), 'example.'+ %w[org com net].shuffle.first].join('@')
+ end
+
def user_name(name = nil)
return name.scan(/\w+/).shuffle.join(%w(. _).sample).downcase if name
View
@@ -1,3 +1,3 @@
module Faker #:nodoc:
- VERSION = "1.0.0"
+ VERSION = "1.0.1"
end
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -14,6 +14,10 @@ def test_free_email
assert @tester.free_email.match(/.+@(gmail|hotmail|yahoo)\.com/)
end
+ def test_safe_email
+ assert @tester.safe_email.match(/.+@example.(com|net|org)/)
+ end
+
def test_user_name
assert @tester.user_name.match(/[a-z]+((_|\.)[a-z]+)?/)
end
@@ -35,4 +35,10 @@ def test_street_address_optionally_provides_secondary_address
assert_match(/Wide Cheerful Path \d \(Green Door\)/, Faker::Address.street_address(:include_secondary))
end
end
+
+ def test_street_address_with_locale_fallback
+ I18n.with_locale('en-gb') do
+ assert_match(/^\d+ \w+ \w+/, Faker::Address.street_address)
+ end
+ end
end
View
@@ -33,7 +33,7 @@
<h1>faker</h1>
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/faker"; return false'>
<p>Get Version</p>
- <a href="http://rubyforge.org/projects/faker" class="numbers">1.0.0</a>
+ <a href="https://github.com/stympy/faker/" class="numbers">1.0.1</a>
</div>
<h2>What</h2>
<p>Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc. The port was motivated by a need for a bunch of fake data to make good-looking screenshots for <a href="http://catchthebest.com">Catch the Best</a>. :)</p>
View
@@ -33,7 +33,7 @@
<h1><%= title %></h1>
<div id="version" class="clickable" onclick='document.location = "<%= download %>"; return false'>
<p>Get Version</p>
- <a href="<%= download %>" class="numbers"><%= version %></a>
+ <a href="https://github.com/stympy/faker/" class="numbers"><%= version %></a>
</div>
<%= body %>
<p class="coda">

0 comments on commit 40d640c

Please sign in to comment.