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).
-
#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
Adds a list of values to a sequence belonging to field on disk.
-
#add_no_duplicates(field, values) ⇒ Object
Adds a list of values to a sequence belonging to field, eliminating duplicates, on disk Returns a list of all values that were added (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’ Returns self.
-
#rm(field, values) ⇒ Object
Removes a field to a sequence of values on disk Returns a list of the values that were removed (could be found).
-
#set(field, value) ⇒ Object
Sets the specified field to the specified value in the file on disk.
Constructor Details
#initialize(file_path = "./.torqueinfo.yaml", file_system = FileSystem.new) ⇒ TorqueInfoParser
Creates a new parser. Does not parse the file
41 42 43 44 45 |
# File 'lib/torque/torque_info_parser.rb', line 41 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 |
#output_dir ⇒ Object (readonly)
The output_dir field (String)
30 31 32 |
# File 'lib/torque/torque_info_parser.rb', line 30 def output_dir @output_dir end |
#project ⇒ Object (readonly)
The project field (Fixnum)
26 27 28 |
# File 'lib/torque/torque_info_parser.rb', line 26 def project @project end |
#token ⇒ Object (readonly)
The token field (String)
34 35 36 |
# File 'lib/torque/torque_info_parser.rb', line 34 def token @token end |
Instance Method Details
#add(field, values) ⇒ Object
Adds a list of values to a sequence belonging to field on disk
85 86 87 88 89 |
# File 'lib/torque/torque_info_parser.rb', line 85 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
Adds a list of values to a sequence belonging to field, eliminating duplicates, on disk Returns a list of all values that were added (were not duplicates)
94 95 96 97 98 99 100 101 |
# File 'lib/torque/torque_info_parser.rb', line 94 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’ Returns self
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/torque/torque_info_parser.rb', line 51 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 # If cannot parse, ignore contents end @email_address = torque_info_hash["email_address"] @email_password = torque_info_hash["email_password"] @email_to = torque_info_hash["email_to"] @project = torque_info_hash["project"] @output_dir = torque_info_hash["output_dir"] @token = torque_info_hash["token"] self end |
#rm(field, values) ⇒ Object
Removes a field to a sequence of values on disk Returns a list of the values that were removed (could be found)
106 107 108 109 110 111 112 113 |
# File 'lib/torque/torque_info_parser.rb', line 106 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
Sets the specified field to the specified value in the file on disk
77 78 79 80 81 |
# File 'lib/torque/torque_info_parser.rb', line 77 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 |