Class: FilterRename::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_rename/utils.rb

Class Method Summary collapse

Class Method Details

.changed_tags(fp, old_data = {}, header = true) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/filter_rename/utils.rb', line 183

def self.changed_tags(fp, old_data = {}, header = true)
  Messages.ok "<#{fp.source.filename}> tags changed:" if header
  old_source = old_data.empty? ? fp.source.values : old_data

  fp.dest.values.each do |k, v|
    puts "    #{k}: ".rjust(15, ' ').bold.green + (old_source[k].to_s.empty? ? ' ~ '.bold.red : old_source[k].to_s) + ' => '.bold.green + v.to_s if ((v.to_s != old_source[k].to_s) && fp.source.writable?(k) && fp.source.custom?(k))
  end
end

.config_list(items, color = :green, ch = '>') ⇒ Object



226
227
228
# File 'lib/filter_rename/utils.rb', line 226

def self.config_list(items, color = :green, ch = '>')
  items.instance_variables.each { |k| Messages.item("#{k.to_s.gsub(/@/, '')}: #{items.instance_variable_get(k)}", color, ch) }
end

.config_multilist(items, color = :green, ch = '>') ⇒ Object



230
231
232
# File 'lib/filter_rename/utils.rb', line 230

def self.config_multilist(items, color = :green, ch = '>')
  items.instance_variables.each { |k| Messages.item("#{k.to_s.gsub(/@/, '')}: [#{items.instance_variable_get(k).keys.join(', ')}]", color, ch) }
end

.diff(fp) ⇒ Object



154
155
156
# File 'lib/filter_rename/utils.rb', line 154

def self.diff(fp)
  puts fp.diff
end

.error(e) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/filter_rename/utils.rb', line 134

def self.error(e)
  if e.class == String
    puts '[E] '.bold.red + e
  else
    STDERR.puts 'Error! '.bold.red + e.message
  end
end

.file_exists(fp) ⇒ Object



192
193
194
# File 'lib/filter_rename/utils.rb', line 192

def self.file_exists(fp)
  Messages.error "<#{fp.source.filename}> can't be renamed in <#{fp.dest.filename}>, it exists!"
end

.file_hash(fp, hash_type, cached = nil) ⇒ Object

Raises:



196
197
198
199
200
201
202
203
204
# File 'lib/filter_rename/utils.rb', line 196

def self.file_hash(fp, hash_type, cached = nil)
  raise UnknownHashCode, hash_type unless [:sha1, :sha2, :md5].include?(hash_type.to_sym)
  klass = Object.const_get("Digest::#{hash_type.to_s.upcase}")
  hash_src = klass.file fp.source.filename
  hash_dest = cached ? klass.file(cached.original) : klass.file(fp.dest.filename)

  puts "    #{hash_src == hash_dest ? '[=]'.green : '[>]'.red} #{hash_type.to_s.upcase} source: #{hash_src.to_s.send(hash_src == hash_dest ? :green : :red)}"
  puts "    #{hash_src == hash_dest ? '[=]'.green : '[<]'.red} #{hash_type.to_s.upcase} dest:   #{hash_dest.to_s.send(hash_src == hash_dest ? :green : :red)}"
end

.item(i, color = :green, ch = '>') ⇒ Object



218
219
220
# File 'lib/filter_rename/utils.rb', line 218

def self.item(i, color = :green, ch = '>')
  puts "[#{ch}] ".bold.send(color) + i
end

.label(text) ⇒ Object



175
176
177
# File 'lib/filter_rename/utils.rb', line 175

def self.label(text)
  puts "#{'[/]'.bold.blue} #{text}"
end

.list(items, color = :green, ch = '>') ⇒ Object



222
223
224
# File 'lib/filter_rename/utils.rb', line 222

def self.list(items, color = :green, ch = '>')
  items.each { |x| Messages.item(x, color, ch) }
end

.long_targets(ff) ⇒ Object



212
213
214
215
216
# File 'lib/filter_rename/utils.rb', line 212

def self.long_targets(ff)
  self.list ff.targets[:readonly].map { |s| "<#{s.to_s.delete('@')}>" }, :red, '-'
  self.list ff.targets[:writable].map { |s| "<#{s.to_s.delete('@')}>" }, :green, '+'
  puts ''
end

.multi(m) ⇒ Object



150
151
152
# File 'lib/filter_rename/utils.rb', line 150

def self.multi(m)
  puts '[*] '.bold.magenta + m
end

.ok(m) ⇒ Object



146
147
148
# File 'lib/filter_rename/utils.rb', line 146

def self.ok(m)
  puts '[V] '.bold.green + m
end

.renamed(fp) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/filter_rename/utils.rb', line 158

def self.renamed(fp)
  if fp.source.full_path != fp.dest.full_path
    Messages.ok "#{fp.source.filename} #{'>'.bold.green} #{fp.dest.full_filename}"
  else
    Messages.ok "#{fp.source.filename} #{'>'.bold.green} #{fp.dest.filename}"
  end
end

.renamed!(old_data, renamed) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/filter_rename/utils.rb', line 166

def self.renamed!(old_data, renamed)
  if old_data[:full_path] != renamed.full_path
    Messages.ok "#{old_data[:filename]} #{'>'.bold.green} #{renamed.full_filename}"
  else
    Messages.ok "#{old_data[:filename]} #{'>'.bold.green} #{renamed.filename}"
  end
end

.short_targets(ff) ⇒ Object



206
207
208
209
210
# File 'lib/filter_rename/utils.rb', line 206

def self.short_targets(ff)
  self.list [ff.targets[:readonly].map { |s| "<#{s.to_s.delete('@')}>"}.join(', ')], :red, '-'
  self.list [ff.targets[:writable].map { |s| "<#{s.to_s.delete('@')}>"}.join(', ')], :green, '+'
  puts ''
end

.skipping(fp) ⇒ Object



179
180
181
# File 'lib/filter_rename/utils.rb', line 179

def self.skipping(fp)
  puts '[X] '.bold.yellow + "Skipping <#{fp.source.filename}>, no changes!"
end

.warning(m) ⇒ Object



142
143
144
# File 'lib/filter_rename/utils.rb', line 142

def self.warning(m)
  puts '[W] '.bold.yellow + m
end