Class: SnapDiff::ScreenshotNamer

Inherits:
Object
  • Object
show all
Defined in:
lib/snap_diff/screenshot_namer.rb

Overview

Handles the naming, path generation, and organization of screenshots. This class encapsulates logic related to screenshot sections, groups, and counters, providing a centralized way to determine screenshot filenames and directories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScreenshotNamer

Returns a new instance of ScreenshotNamer.



14
15
16
17
18
# File 'lib/snap_diff/screenshot_namer.rb', line 14

def initialize
  @section = nil
  @group = nil
  @counter = nil
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



12
13
14
# File 'lib/snap_diff/screenshot_namer.rb', line 12

def group
  @group
end

#sectionObject

Returns the value of attribute section.



12
13
14
# File 'lib/snap_diff/screenshot_namer.rb', line 12

def section
  @section
end

Instance Method Details

#directory_partsArray<String>

Returns the directory parts (section and group) for constructing paths.

Returns:

  • (Array<String>)

    An array of directory names.



50
51
52
53
54
55
# File 'lib/snap_diff/screenshot_namer.rb', line 50

def directory_parts
  parts = []
  parts << @section unless @section.nil? || @section.empty?
  parts << @group unless @group.nil? || @group.empty?
  parts
end

#full_name(base_name) ⇒ String

Builds the full, unique name for a screenshot, including any counter.

Parameters:

  • base_name (String)

    The base name for the screenshot.

Returns:

  • (String)

    The full screenshot name.



37
38
39
40
41
42
43
44
45
46
# File 'lib/snap_diff/screenshot_namer.rb', line 37

def full_name(base_name)
  name = base_name.to_s

  if @counter
    name = format("%02i_%s", @counter, name)
    @counter += 1
  end

  File.join(*directory_parts.push(name.to_s))
end