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
132 133 134 135 136 137 138 |
# File 'lib/quick_faker.rb', line 132 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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/quick_faker.rb', line 140 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 ‘
165 166 167 |
# File 'lib/quick_faker.rb', line 165 def scrape(s) s.scan(/(?<=:)\w+/) end |