Class: ShatteredMachine::Io

Inherits:
Object
  • Object
show all
Defined in:
lib/shattered_machine/io.rb

Overview

Find all png or jpg image in a given directory. Generate output filename that doesn’t overwrite existing file.

Defined Under Namespace

Classes: Paths

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, output_folder, output_filename) ⇒ Io

Returns a new instance of Io.

Parameters:

  • input_path (string)

    input file or directory

  • output_folder (string)

    output directory

  • output_filename (string)

    output file name



12
13
14
15
16
# File 'lib/shattered_machine/io.rb', line 12

def initialize(input_path, output_folder, output_filename)
  @input_path = input_path
  @output_folder = output_folder
  @output_filename = output_filename
end

Instance Attribute Details

#output_filenameObject

Returns the value of attribute output_filename.



7
8
9
# File 'lib/shattered_machine/io.rb', line 7

def output_filename
  @output_filename
end

Instance Method Details

#jpg_imagesArray<Paths>

Returns list of all jpg images in input_path.

Returns:

  • (Array<Paths>)

    list of all jpg images in input_path



28
29
30
31
32
33
34
# File 'lib/shattered_machine/io.rb', line 28

def jpg_images
  return single_image_io if extension_included?(JPG_EXTENSIONS, @input_path)

  images_in_directory(JPG_EXTENSIONS).map do |img|
    Paths.new("#{@input_path}/#{img}", generate_output_filename(img))
  end
end

#png_imagesArray<Paths>

Returns list of all png images in input_path.

Returns:

  • (Array<Paths>)

    list of all png images in input_path



19
20
21
22
23
24
25
# File 'lib/shattered_machine/io.rb', line 19

def png_images
  return single_image_io if extension_included?(PNG_EXTENSIONS, @input_path)

  images_in_directory(PNG_EXTENSIONS).map do |img|
    Paths.new("#{@input_path}/#{img}", generate_output_filename(img))
  end
end