Class: Csvtool::Domain::Shared::OutputDestination

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtool/domain/shared/output_destination.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode:, path: nil) ⇒ OutputDestination

Returns a new instance of OutputDestination.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/csvtool/domain/shared/output_destination.rb', line 17

def initialize(mode:, path: nil)
  raise ArgumentError, "invalid output mode" unless i[console file].include?(mode)
  raise ArgumentError, "file output path cannot be empty" if mode == :file && path.to_s.empty?

  @mode = mode
  @path = path
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



7
8
9
# File 'lib/csvtool/domain/shared/output_destination.rb', line 7

def mode
  @mode
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/csvtool/domain/shared/output_destination.rb', line 7

def path
  @path
end

Class Method Details

.consoleObject



9
10
11
# File 'lib/csvtool/domain/shared/output_destination.rb', line 9

def self.console
  new(mode: :console)
end

.file(path:) ⇒ Object



13
14
15
# File 'lib/csvtool/domain/shared/output_destination.rb', line 13

def self.file(path:)
  new(mode: :file, path: path)
end

Instance Method Details

#console?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/csvtool/domain/shared/output_destination.rb', line 29

def console?
  @mode == :console
end

#file?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/csvtool/domain/shared/output_destination.rb', line 25

def file?
  @mode == :file
end