Class: FakerData
- Inherits:
-
Object
- Object
- FakerData
- Defined in:
- lib/quick_faker.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(topics = nil, filepath: '/tmp/faker.yaml') ⇒ FakerData
constructor
A new instance of FakerData.
-
#scrape(s) ⇒ Object
returns a list of topics ‘.
Constructor Details
#initialize(topics = nil, filepath: '/tmp/faker.yaml') ⇒ FakerData
Returns a new instance of FakerData.
116 117 118 119 120 121 122 |
# File 'lib/quick_faker.rb', line 116 def initialize(topics=nil, filepath: '/tmp/faker.yaml') topics ||= %w(Address Company Date Educator Gender Hobby Name Relationship Vehicle) @url = 'https://raw.githubusercontent.com/faker-ruby/faker/master/doc/default/' @topics, @filepath = topics, filepath end |
Instance Method Details
#build ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/quick_faker.rb', line 124 def build() a2 = @topics.map do |rawname| puts rawname + '...' name = rawname.downcase url = @url + name + '.md' begin s, _ = RXFReader.read url rescue next end a = s.scan(/Faker::#{rawname}\S+/) a.reject! {|x| x[-1] == ':'} [rawname, a] end File.write @filepath, a2.compact.to_yaml puts 'written to ' + @filepath end |
#scrape(s) ⇒ Object
returns a list of topics ‘
149 150 151 |
# File 'lib/quick_faker.rb', line 149 def scrape(s) s.scan(/(?<=:)\w+/) end |