Class: QuickFaker
- Inherits:
-
Object
- Object
- QuickFaker
- Defined in:
- lib/quick_faker.rb
Instance Method Summary collapse
-
#initialize(locale = 'en-GB') ⇒ QuickFaker
constructor
A new instance of QuickFaker.
- #lookup(s, context = nil) ⇒ Object
- #lookup2(s) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(locale = 'en-GB') ⇒ QuickFaker
Returns a new instance of QuickFaker.
12 13 14 15 16 17 18 19 20 |
# File 'lib/quick_faker.rb', line 12 def initialize(locale='en-GB') Faker::Config.locale = locale s = File.join(File.dirname(__FILE__), '..', 'data', 'faker.yaml') a = YAML.load(File.read(s)) load_methods(a) end |
Instance Method Details
#lookup(s, context = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/quick_faker.rb', line 22 def lookup(s, context=nil) found = @h[s.to_sym] if found[0].is_a? Array h = found.map {|x| x.last[/[^:]+(?=\.)/].downcase.to_sym}.zip(found.map(&:first)).to_h if context then h[context].call elsif h.keys.include? :name h[:name].call else raise 'provide context! options: ' + h.keys.map(&:to_s).join(', ') end else found[0].call end end |
#lookup2(s) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/quick_faker.rb', line 39 def lookup2(s) found = @h[s.to_sym] if found[0].is_a? Array then found.map(&:last) else found.last end end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/quick_faker.rb', line 50 def to_h() @h end |