Class: UserAgentGenerator::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/User_Agent_Generator/output.rb

Overview

:nodoc:

Constant Summary collapse

PATH_TO_WORKING_DIRECTORY =
Dir.pwd
MESSAGE =
"You can find the user agent strings in the path: \
#{PATH_TO_WORKING_DIRECTORY}/data/"
PATH =
'data/'
FILENAME =
'user_agent_strings.txt'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Output

Returns a new instance of Output.



10
11
12
# File 'lib/User_Agent_Generator/output.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#append_to_fileObject



24
25
26
# File 'lib/User_Agent_Generator/output.rb', line 24

def append_to_file
  File.open(PATH + FILENAME, 'a')
end

#create_new_fileObject



28
29
30
31
32
33
34
35
36
# File 'lib/User_Agent_Generator/output.rb', line 28

def create_new_file
  path = PATH
  unless File.directory?(Dir.pwd + path)
    FileUtils.mkdir_p(path)
  end

  path << FILENAME
  File.new(path, 'w')
end

#to_file(agent_string) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/User_Agent_Generator/output.rb', line 14

def to_file(agent_string)
  output_to_render = MESSAGE

  exists = File.exist?(PATH + FILENAME)
  file = exists ? append_to_file : create_new_file
  write_to_file(file, agent_string)

  output_to_render << FILENAME
end

#write_to_file(file, agent_string) ⇒ Object



38
39
40
# File 'lib/User_Agent_Generator/output.rb', line 38

def write_to_file(file, agent_string)
  file.puts(agent_string)
end