Class: Torque::TorqueInfoParser
- Inherits:
-
Object
- Object
- Torque::TorqueInfoParser
- Defined in:
- lib/torque/torque_info_parser.rb
Overview
Parses the raw contents of the torque info file Stores each of the fields in .torqueinfo.yaml as publicly accessible fields
Instance Attribute Summary collapse
-
#email_address ⇒ Object
readonly
The email_address field (String).
-
#email_password ⇒ Object
readonly
The email_password field (String).
-
#email_to ⇒ Object
readonly
The email_to field (String or Array).
-
#format ⇒ Object
readonly
The format string to use for the project.
-
#output_dir ⇒ Object
readonly
The output_dir field (String).
-
#project ⇒ Object
readonly
The project field (Fixnum).
-
#token ⇒ Object
readonly
The token field (String).
Instance Method Summary collapse
- #add(field, values) ⇒ Object
-
#add_no_duplicates(field, values) ⇒ Object
A list of all values that were added (ie that were not duplicates).
-
#initialize(file_path = "./.torqueinfo.yaml", file_system = FileSystem.new) ⇒ TorqueInfoParser
constructor
Creates a new parser.
-
#parse ⇒ Object
Parses the file, storing the results as public instnance fields Stores each field with no corresponding value in the file as ‘nil’.
-
#rm(field, values) ⇒ Object
A list of the values that were removed (ie that could be found).
- #set(field, value) ⇒ Object
Constructor Details
#initialize(file_path = "./.torqueinfo.yaml", file_system = FileSystem.new) ⇒ TorqueInfoParser
Creates a new parser. Does not parse the file
45 46 47 48 49 |
# File 'lib/torque/torque_info_parser.rb', line 45 def initialize(file_path = "./.torqueinfo.yaml", file_system = FileSystem.new) @file_path = file_path @fs = file_system end |
Instance Attribute Details
#email_address ⇒ Object (readonly)
The email_address field (String)
14 15 16 |
# File 'lib/torque/torque_info_parser.rb', line 14 def email_address @email_address end |
#email_password ⇒ Object (readonly)
The email_password field (String)
18 19 20 |
# File 'lib/torque/torque_info_parser.rb', line 18 def email_password @email_password end |
#email_to ⇒ Object (readonly)
The email_to field (String or Array)
22 23 24 |
# File 'lib/torque/torque_info_parser.rb', line 22 def email_to @email_to end |
#format ⇒ Object (readonly)
The format string to use for the project
26 27 28 |
# File 'lib/torque/torque_info_parser.rb', line 26 def format @format end |
#output_dir ⇒ Object (readonly)
The output_dir field (String)
34 35 36 |
# File 'lib/torque/torque_info_parser.rb', line 34 def output_dir @output_dir end |
#project ⇒ Object (readonly)
The project field (Fixnum)
30 31 32 |
# File 'lib/torque/torque_info_parser.rb', line 30 def project @project end |
#token ⇒ Object (readonly)
The token field (String)
38 39 40 |
# File 'lib/torque/torque_info_parser.rb', line 38 def token @token end |
Instance Method Details
#add(field, values) ⇒ Object
93 94 95 96 97 |
# File 'lib/torque/torque_info_parser.rb', line 93 def add(field, values) file_string = @fs.file_read(@file_path) new_file_string = add_string(field, values, file_string) @fs.file_write(@file_path, new_file_string) end |
#add_no_duplicates(field, values) ⇒ Object
Returns A list of all values that were added (ie that were not duplicates).
104 105 106 107 108 109 110 111 |
# File 'lib/torque/torque_info_parser.rb', line 104 def add_no_duplicates(field, values) file_string = @fs.file_read(@file_path) values_copy = values.clone new_file_string = add_no_duplicates_string(field, values_copy, file_string) @fs.file_write(@file_path, new_file_string) values_copy end |
#parse ⇒ Object
Parses the file, storing the results as public instnance fields Stores each field with no corresponding value in the file as ‘nil’
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/torque/torque_info_parser.rb', line 56 def parse if !@fs.path_exist?(@file_path) directory = File.(File.dirname(@file_path)) raise MissingTorqueInfoFileError.new "'#{directory}' is not configured for Torque" end torque_info_hash = {} begin torque_info_hash = YAML::load(@fs.file_read(@file_path)) || {} rescue Psych::SyntaxError # TODO Implement custom error, raise/rescue paths to catch this problem end @email_address = torque_info_hash["email_address"] @email_password = torque_info_hash["email_password"] @email_to = torque_info_hash["email_to"] @format = torque_info_hash["format"] @project = torque_info_hash["project"] @output_dir = torque_info_hash["output_dir"] @token = torque_info_hash["token"] self end |
#rm(field, values) ⇒ Object
Returns A list of the values that were removed (ie that could be found).
118 119 120 121 122 123 124 125 |
# File 'lib/torque/torque_info_parser.rb', line 118 def rm(field, values) file_string = @fs.file_read(@file_path) values_copy = values.clone new_file_string = rm_string(field, values_copy, file_string) @fs.file_write(@file_path, new_file_string) values_copy end |
#set(field, value) ⇒ Object
84 85 86 87 88 |
# File 'lib/torque/torque_info_parser.rb', line 84 def set(field, value) file_string = @fs.file_read(@file_path) new_file_string = set_string(field, value, file_string) @fs.file_write(@file_path, new_file_string) end |