Sha256: b244e29ead7c00e85985e40002597aa39aabb81551761936e6813fc6fd7b1ea1

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module FileTree
  module ContentGenerator
    LETTERS = ["a".."z", "A".."Z", "0".."9", " ", "\n", "_", "*"].map{|i| Array(i)}.flatten
    CONTENT_TYPES = [:binary, :text, :empty]

    def self.create(type)
      type = CONTENT_TYPES.sample if type == :random

      case type
        when :binary
          create_binary_content
        when :text
          create_text_content
        when :empty
          ""
        else
          raise(ArgumentError, "Unsupported content type: #{type}")
      end
    end

    def self.create_binary_content
      Random.new.bytes(random_file_size)
    end

    def self.create_text_content
      (1..random_file_size).map{LETTERS.sample}.join
    end

    def self.random_file_size
      rand(Defaults.min_file_size..Defaults.max_file_size)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
file_tree-0.1.0 lib/file_tree/content_generator.rb