Class: Faker::File
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.dir(segment_count: 3, root: nil, directory_separator: ::File::Separator) ⇒ String
Produces a random directory name.
-
.extension ⇒ String
Produces a random file extension.
-
.file_name(dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator) ⇒ String
Produces a random file name.
-
.mime_type(media_type: nil) ⇒ String
Produces a random mime type.
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
.dir(segment_count: 3, root: nil, directory_separator: ::File::Separator) ⇒ String
Produces a random directory name.
21 22 23 24 25 26 27 28 |
# File 'lib/faker/default/file.rb', line 21 def dir(segment_count: 3, root: nil, directory_separator: ::File::Separator) Array .new(segment_count) { Faker::Internet.slug } .unshift(root) .compact .join(directory_separator) .squeeze(directory_separator) end |
.extension ⇒ String
Produces a random file extension.
39 40 41 |
# File 'lib/faker/default/file.rb', line 39 def extension fetch('file.extension') end |
.file_name(dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator) ⇒ String
Produces a random file name.
72 73 74 75 76 77 78 |
# File 'lib/faker/default/file.rb', line 72 def file_name(dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator) dir ||= dir(segment_count: 1) name ||= Faker::Lorem.word.downcase ext ||= extension [dir, name].join(directory_separator) + ".#{ext}" end |
.mime_type(media_type: nil) ⇒ String
Produces a random mime type.
52 53 54 |
# File 'lib/faker/default/file.rb', line 52 def mime_type(media_type: nil) media_type ? fetch("file.mime_type.#{media_type}") : sample(sample(translate('faker.file.mime_type').values)) end |