Class: SnapDiff::ScreenshotNamer
- Inherits:
-
Object
- Object
- SnapDiff::ScreenshotNamer
- 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
-
#group ⇒ Object
Returns the value of attribute group.
-
#section ⇒ Object
Returns the value of attribute section.
Instance Method Summary collapse
-
#directory_parts ⇒ Array<String>
Returns the directory parts (section and group) for constructing paths.
-
#full_name(base_name) ⇒ String
Builds the full, unique name for a screenshot, including any counter.
-
#initialize ⇒ ScreenshotNamer
constructor
A new instance of ScreenshotNamer.
Constructor Details
#initialize ⇒ ScreenshotNamer
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
#group ⇒ Object
Returns the value of attribute group.
12 13 14 |
# File 'lib/snap_diff/screenshot_namer.rb', line 12 def group @group end |
#section ⇒ Object
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_parts ⇒ Array<String>
Returns the directory parts (section and group) for constructing paths.
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.
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 |