Class: Faker::Json
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Hash{String => String}
Produces a random nested JSON formatted string that can take JSON as an additional argument.
-
.shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Hash{String => String}
Produces a random simple JSON formatted string.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, 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' }) ⇒ Hash{String => String}
Produces a random nested JSON formatted string that can take JSON as an additional argument.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/faker/default/json.rb', line 69 def add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) [:key] = "Faker::#{[:key]}" [:value] = "Faker::#{[:value]}" hash = JSON.parse(json) hash.each_key do |key| add_hash_to_bottom(hash, [key], width, ) end JSON.generate(hash) end |
.shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) ⇒ Hash{String => String}
Produces a random simple JSON formatted string.
23 24 25 26 27 28 29 |
# File 'lib/faker/default/json.rb', line 23 def shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' }) [:key] = "Faker::#{[:key]}" [:value] = "Faker::#{[:value]}" hash = build_shallow_hash(width, ) JSON.generate(hash) end |