Class: String
- Inherits:
-
Object
- Object
- String
- Includes:
- ReadableVariables
- Defined in:
- lib/filter_rename/utils.rb
Overview
String class patch.
Instance Method Summary collapse
- #bg_black ⇒ Object
- #bg_blue ⇒ Object
- #bg_brown ⇒ Object
- #bg_cyan ⇒ Object
- #bg_gray ⇒ Object
- #bg_green ⇒ Object
- #bg_magenta ⇒ Object
- #bg_red ⇒ Object
- #black ⇒ Object
- #blue ⇒ Object
- #bold ⇒ Object
- #change_date_format(args) ⇒ Object
- #clean ⇒ Object
- #cr ⇒ Object
- #cyan ⇒ Object
- #get_number(idx) ⇒ Object
- #gray ⇒ Object
- #green ⇒ Object
- #magenta ⇒ Object
- #map_number_with_index(&block) ⇒ Object
- #new_line ⇒ Object
- #numbers ⇒ Object
- #parametrize ⇒ Object
- #red ⇒ Object
- #reverse_color ⇒ Object
-
#to_boolean ⇒ Object
rubocop:disable Naming/PredicateMethod.
-
#to_filter ⇒ Object
rubocop:enable Naming/PredicateMethod.
- #to_switch ⇒ Object
- #yellow ⇒ Object
Instance Method Details
#bg_black ⇒ Object
97 98 99 |
# File 'lib/filter_rename/utils.rb', line 97 def bg_black "\033[40m#{self}\0330m" end |
#bg_blue ⇒ Object
113 114 115 |
# File 'lib/filter_rename/utils.rb', line 113 def bg_blue "\033[44m#{self}\033[0m" end |
#bg_brown ⇒ Object
109 110 111 |
# File 'lib/filter_rename/utils.rb', line 109 def bg_brown "\033[43m#{self}\033[0m" end |
#bg_cyan ⇒ Object
121 122 123 |
# File 'lib/filter_rename/utils.rb', line 121 def bg_cyan "\033[46m#{self}\033[0m" end |
#bg_gray ⇒ Object
125 126 127 |
# File 'lib/filter_rename/utils.rb', line 125 def bg_gray "\033[47m#{self}\033[0m" end |
#bg_green ⇒ Object
105 106 107 |
# File 'lib/filter_rename/utils.rb', line 105 def bg_green "\033[42m#{self}\033[0m" end |
#bg_magenta ⇒ Object
117 118 119 |
# File 'lib/filter_rename/utils.rb', line 117 def bg_magenta "\033[45m#{self}\033[0m" end |
#bg_red ⇒ Object
101 102 103 |
# File 'lib/filter_rename/utils.rb', line 101 def bg_red "\033[41m#{self}\033[0m" end |
#black ⇒ Object
65 66 67 |
# File 'lib/filter_rename/utils.rb', line 65 def black "\033[30m#{self}\033[0m" end |
#blue ⇒ Object
81 82 83 |
# File 'lib/filter_rename/utils.rb', line 81 def blue "\033[34m#{self}\033[0m" end |
#bold ⇒ Object
129 130 131 |
# File 'lib/filter_rename/utils.rb', line 129 def bold "\033[1m#{self}\033[22m" end |
#change_date_format(args) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/filter_rename/utils.rb', line 167 def change_date_format(args) format_src = args[:format_src] format_dest = args[:format_dest] short_months = args[:short_months] long_months = args[:long_months] long_days = args[:long_days] short_days = args[:short_days] str = clone regexp = format_src.gsub("<B>", "(#{long_months.join("|")})").gsub("<b>", "(#{short_months.join("|")})") .gsub("<A>", "(#{long_days.join("|")})").gsub("<a>", "(#{short_days.join("|")})") .gsub("<Y>", "[0-9]{4,4}").gsub(/<(d|m|y|H|I|M|S|U)>/, "[0-9]{2,2}") .gsub("<u>", "[0-9]{1,1}") to_replace = str.scan(Regexp.new("(#{regexp})", true)) unless to_replace.empty? to_replace = to_replace.pop template = format_src.gsub(/<([a-zA-Z])>/, '%\1') d = Date.strptime(to_replace[0], template) str.gsub! to_replace[0], d.strftime(format_dest.gsub(/<([a-zA-Z])>/, '%\1')) end str end |
#clean ⇒ Object
141 142 143 |
# File 'lib/filter_rename/utils.rb', line 141 def clean "\e[K#{self}" end |
#cr ⇒ Object
137 138 139 |
# File 'lib/filter_rename/utils.rb', line 137 def cr "\r#{self}" end |
#cyan ⇒ Object
89 90 91 |
# File 'lib/filter_rename/utils.rb', line 89 def cyan "\033[36m#{self}\033[0m" end |
#get_number(idx) ⇒ Object
199 200 201 |
# File 'lib/filter_rename/utils.rb', line 199 def get_number(idx) scan(/\d+/)[idx] end |
#gray ⇒ Object
93 94 95 |
# File 'lib/filter_rename/utils.rb', line 93 def gray "\033[37m#{self}\033[0m" end |
#green ⇒ Object
73 74 75 |
# File 'lib/filter_rename/utils.rb', line 73 def green "\033[32m#{self}\033[0m" end |
#magenta ⇒ Object
85 86 87 |
# File 'lib/filter_rename/utils.rb', line 85 def magenta "\033[35m#{self}\033[0m" end |
#map_number_with_index(&block) ⇒ Object
195 196 197 |
# File 'lib/filter_rename/utils.rb', line 195 def map_number_with_index(&block) gsub(/\d+/).with_index(&block) end |
#new_line ⇒ Object
145 146 147 |
# File 'lib/filter_rename/utils.rb', line 145 def new_line "\n#{self}" end |
#numbers ⇒ Object
203 204 205 |
# File 'lib/filter_rename/utils.rb', line 203 def numbers scan(/\d+/) end |
#parametrize ⇒ Object
149 150 151 |
# File 'lib/filter_rename/utils.rb', line 149 def parametrize split(/(?<!\\),/).map { |x| x.gsub('\,', ",") } end |
#red ⇒ Object
69 70 71 |
# File 'lib/filter_rename/utils.rb', line 69 def red "\033[31m#{self}\033[0m" end |
#reverse_color ⇒ Object
133 134 135 |
# File 'lib/filter_rename/utils.rb', line 133 def reverse_color "\033[7m#{self}\033[27m" end |
#to_boolean ⇒ Object
rubocop:disable Naming/PredicateMethod
154 155 156 |
# File 'lib/filter_rename/utils.rb', line 154 def to_boolean %w[1 true].include? downcase end |
#to_filter ⇒ Object
rubocop:enable Naming/PredicateMethod
159 160 161 |
# File 'lib/filter_rename/utils.rb', line 159 def to_filter Object.const_get("FilterRename::Filters::#{to_s.split(/_|-/).map(&:capitalize).join}") end |
#to_switch ⇒ Object
163 164 165 |
# File 'lib/filter_rename/utils.rb', line 163 def to_switch scan(/[A-Z][a-z0-9]*/).map(&:downcase).join "-" end |
#yellow ⇒ Object
77 78 79 |
# File 'lib/filter_rename/utils.rb', line 77 def yellow "\033[33m#{self}\033[0m" end |