Class: AtticCleanup::Path::Custom
- Inherits:
-
Object
- Object
- AtticCleanup::Path::Custom
- Defined in:
- lib/attic-cleanup/path/custom.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#line_nr ⇒ Object
Returns the value of attribute line_nr.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.all(file) ⇒ Object
Selects every line from the selected file but ignores lines where the first character is ‘#’.
- .check_ignore(file) ⇒ Object
-
.default ⇒ Object
Gets the last line in the default_path.txt file, which is the path to the default route.
- .set_default(value) ⇒ Object
- .set_ignore(value) ⇒ Object
Instance Method Summary collapse
- #check_shortcut(input) ⇒ Object
-
#find_custom ⇒ Object
Gets the custom shortcuts and looks in the custom_paths.txt file if there is a match.
-
#find_line ⇒ Object
Gets a specific line from a file.
-
#write ⇒ Object
Write to the custom_paths.txt file.
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/attic-cleanup/path/custom.rb', line 4 def file @file end |
#line_nr ⇒ Object
Returns the value of attribute line_nr.
4 5 6 |
# File 'lib/attic-cleanup/path/custom.rb', line 4 def line_nr @line_nr end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/attic-cleanup/path/custom.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/attic-cleanup/path/custom.rb', line 4 def path @path end |
Class Method Details
.all(file) ⇒ Object
Selects every line from the selected file but ignores lines where the first character is ‘#’
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/attic-cleanup/path/custom.rb', line 31 def self.all(file) File.open(file, 'r') do |r| line_array = [] while line = r.gets do if line[0..0] == "#" else line_array << line end end line_array end end |
.check_ignore(file) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/attic-cleanup/path/custom.rb', line 90 def self.check_ignore(file) is_file = false lines = [] File.open(MyAttic::IGNORE, 'r') do |r| while line = r.gets do if line == file || line == file+"\n" is_file = true end end end is_file end |
.default ⇒ Object
Gets the last line in the default_path.txt file, which is the path to the default route
8 9 10 11 12 13 14 15 16 |
# File 'lib/attic-cleanup/path/custom.rb', line 8 def self.default File.open(MyAttic::DEFAULT, 'r') do |r| line_array = [] while line = r.gets do line_array << line end line_array.last end end |
Instance Method Details
#check_shortcut(input) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/attic-cleanup/path/custom.rb', line 18 def check_shortcut(input) if input[0..0] == "@" c = AtticCleanup::Path::Custom.new # The input without the first character (the @ sign) c.name = input[1..-1] c.file = MyAttic::CUSTOM input = c.find_custom end input end |
#find_custom ⇒ Object
Gets the custom shortcuts and looks in the custom_paths.txt file if there is a match. If there is it will select that line and extract the shortcut, so only the path remains
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/attic-cleanup/path/custom.rb', line 65 def find_custom File.open(@file, 'r') do |r| k = [] k[0] = nil while line = r.gets do name_count = @name.count("A-z, \s") k << line[0..name_count] this_name = k.last if this_name == @name+" " selected_line = line the_name = this_name end end if selected_line == nil puts "Shortcut not found '@#{@name}'" exit 1 else the_name_count = the_name.count("A-z, \s") line_count = selected_line.count("A-z, \s, '/'") selected_line[the_name_count..line_count-1] end end end |
#find_line ⇒ Object
Gets a specific line from a file
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/attic-cleanup/path/custom.rb', line 45 def find_line File.open(@file, 'r') do |r| k = [] k[0] = nil while line = r.gets do k << line end if k[@line_nr] == nil "This line does not exist." elsif k[@line_nr] == "\n" "Empty" else k[@line_nr] end end end |
#write ⇒ Object
Write to the custom_paths.txt file
104 105 106 107 108 |
# File 'lib/attic-cleanup/path/custom.rb', line 104 def write File.open(@file, 'a') do |w| w.write("\n"+ @name + " " + @path) end end |