Class: NeedForType::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/need_for_type/file_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileManager

Returns a new instance of FileManager.



5
6
7
# File 'lib/need_for_type/file_manager.rb', line 5

def initialize()
  @path = "#{NeedForType::GEM_ROOT}/assets/texts/"
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/need_for_type/file_manager.rb', line 3

def text
  @text
end

#text_idObject

Returns the value of attribute text_id.



3
4
5
# File 'lib/need_for_type/file_manager.rb', line 3

def text_id
  @text_id
end

Instance Method Details

#read_random_textObject



9
10
11
12
13
# File 'lib/need_for_type/file_manager.rb', line 9

def read_random_text
  directory_count = Dir[File.join(@path, '**', '*')].count
  @text_id = rand(1..directory_count)
  @text = File.read("#{@path}/text-#{@text_id}.txt").strip
end