Class: Chaussettes::Input

Inherits:
Object
  • Object
show all
Includes:
CommonOptions
Defined in:
lib/chaussettes/input.rb

Overview

Represents an input to an operation

Instance Method Summary collapse

Methods included from CommonOptions

#bits, #channels, #encoding, #endian, #rate, #reverse_bits, #reverse_nibbles, #type

Constructor Details

#initialize(source = nil, device: nil) ⇒ Input

Returns a new instance of Input.



9
10
11
12
13
14
15
# File 'lib/chaussettes/input.rb', line 9

def initialize(source = nil, device: nil)
  @source = _translate_source(source) ||
            _translate_device(device) ||
            raise(ArgumentError, 'unsupported source')

  @arguments = []
end

Instance Method Details

#_translate_device(device) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/chaussettes/input.rb', line 25

def _translate_device(device)
  if device == :default
    '--default-device'
  elsif device == :stdin
    '-'
  elsif device.nil? || device == :null
    '--null'
  end
end

#_translate_source(source) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/chaussettes/input.rb', line 17

def _translate_source(source)
  if source.is_a?(String)
    source
  elsif source.respond_to?(:command)
    "|#{source.command}"
  end
end

#commandsObject



35
36
37
# File 'lib/chaussettes/input.rb', line 35

def commands
  [ *@arguments, @source ]
end

#ignore_lengthObject



39
40
41
42
# File 'lib/chaussettes/input.rb', line 39

def ignore_length
  @arguments << '--ignore-length'
  self
end

#volume(factor) ⇒ Object



44
45
46
47
# File 'lib/chaussettes/input.rb', line 44

def volume(factor)
  @arguments << '--volume' << factor
  self
end