1 | class String |
---|
2 | # see if string has any content |
---|
3 | def blank?; self.length.zero?; end |
---|
4 | |
---|
5 | # strip space after :, remove newlines, replace multiple spaces with only one space, remove comments |
---|
6 | def strip_space! |
---|
7 | replace self.gsub(/:\s*/, ":").gsub(/\n/, "").gsub(/\s+/, " ").gsub(/(\/\*).*?(\*\/)/, "") |
---|
8 | end |
---|
9 | |
---|
10 | # remove newlines, insert space after comma, replace two spaces with one space after comma |
---|
11 | def strip_selector_space! |
---|
12 | replace self.gsub(/\n/, "").gsub(",", ", ").gsub(", ", ", ") |
---|
13 | end |
---|
14 | |
---|
15 | # remove leading whitespace, remove end whitespace |
---|
16 | def strip_side_space! |
---|
17 | replace self.gsub(/^\s+/, "").gsub(/\s+$/, $/) |
---|
18 | end |
---|
19 | end |
---|
20 | |
---|
21 | class NilClass |
---|
22 | def blank? |
---|
23 | true |
---|
24 | end |
---|
25 | end |
---|
26 | |
---|
27 | class File |
---|
28 | # string output from file |
---|
29 | def self.path_to_string(path) |
---|
30 | File.new(path).read |
---|
31 | end |
---|
32 | |
---|
33 | # saves a string to a specified file path |
---|
34 | def self.string_to_file(string, path) |
---|
35 | directory = File.dirname(path) |
---|
36 | FileUtils.mkdir_p directory unless File.directory?(directory) |
---|
37 | File.open(path, "w") { |f| f << string } |
---|
38 | end |
---|
39 | end |
---|