Class: Faker::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/json.rb

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.add_depth_to_json(json = shallow_json, width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/faker/default/json.rb', line 14

def add_depth_to_json(json = shallow_json, width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' })
  options[:key] = options[:key].prepend('Faker::')
  options[:value] = options[:value].prepend('Faker::')

  hash = JSON.parse(json)
  hash.each do |key, _|
    add_hash_to_bottom(hash, [key], width, options)
  end
  JSON.generate(hash)
end

.shallow_json(width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/faker/default/json.rb', line 6

def shallow_json(width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' })
  options[:key] = options[:key].prepend('Faker::')
  options[:value] = options[:value].prepend('Faker::')

  hash = build_shallow_hash(width, options)
  JSON.generate(hash)
end