Class: UserAgentGenerator::Output
- Inherits:
-
Object
- Object
- UserAgentGenerator::Output
- 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
- #append_to_file ⇒ Object
- #create_new_file ⇒ Object
-
#initialize(options) ⇒ Output
constructor
A new instance of Output.
- #to_file(agent_string) ⇒ Object
- #write_to_file(file, agent_string) ⇒ Object
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() = end |
Instance Method Details
#append_to_file ⇒ Object
24 25 26 |
# File 'lib/User_Agent_Generator/output.rb', line 24 def append_to_file File.open(PATH + FILENAME, 'a') end |
#create_new_file ⇒ Object
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 |