Fixed some rubocop violations, cleaned up some bad code smell with structs
This commit is contained in:
parent
6d893e3aeb
commit
84dda881bc
|
@ -11,14 +11,21 @@ class Stickerizer
|
||||||
Extension.new(filename[-4..-1])
|
Extension.new(filename[-4..-1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ImageFormat = Struct.new(:size, :format)
|
||||||
|
|
||||||
|
def telegram_format
|
||||||
|
ImageFormat.new('512x512', 'PNG')
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@convert = DirTermine.new
|
@convert = DirTermine.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def stickerize(pic_file, save_dir)
|
def stickerize(pic_file, save_dir)
|
||||||
|
sticker_format = telegram_format
|
||||||
image = MiniMagick::Image.open(pic_file)
|
image = MiniMagick::Image.open(pic_file)
|
||||||
image.resize '512x512'
|
image.resize sticker_format.size
|
||||||
image.format 'PNG'
|
image.format sticker_format.format
|
||||||
image.write(save_dir + '/' + stickername(pic_file))
|
image.write(save_dir + '/' + stickername(pic_file))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -37,7 +44,7 @@ class Stickerizer
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid?(file)
|
def valid?(file)
|
||||||
#TODO: Change this to check file types instead of relying on filenames
|
# TODO: Change this to check file types instead of relying on filenames
|
||||||
valid = false
|
valid = false
|
||||||
file_info = file_ext(file)
|
file_info = file_ext(file)
|
||||||
valid = true if file_info.extension == '.png'
|
valid = true if file_info.extension == '.png'
|
||||||
|
@ -52,7 +59,6 @@ class Stickerizer
|
||||||
destination = dest_dir
|
destination = dest_dir
|
||||||
puts "#{origin} is origin"
|
puts "#{origin} is origin"
|
||||||
Dir.children(origin).each do |unstickerized|
|
Dir.children(origin).each do |unstickerized|
|
||||||
puts "#{unstickerized} OOA"
|
|
||||||
next unless valid?(unstickerized)
|
next unless valid?(unstickerized)
|
||||||
|
|
||||||
stickerize("#{origin}/#{unstickerized}", destination)
|
stickerize("#{origin}/#{unstickerized}", destination)
|
||||||
|
|
Loading…
Reference in a new issue