Class: Subjuster::UserInput
- Inherits:
-
Object
- Object
- Subjuster::UserInput
- Defined in:
- lib/subjuster/user_input.rb
Overview
Handle User Input
Being a CLI tool, Subjuster is supposed to take input from ARGV This module will get those data via arguments to the constructor method.
For Example:
inputs = UserInput.new(source: ARGV[0], target: ARGV[1], adjustment_in_sec: ARGV[2])
inputs.valid? # => true / false
Instance Attribute Summary collapse
-
#adjustment_in_sec ⇒ Object
readonly
Returns the value of attribute adjustment_in_sec.
-
#source_filepath ⇒ Object
readonly
Returns the value of attribute source_filepath.
-
#target_filepath ⇒ Object
readonly
Returns the value of attribute target_filepath.
Instance Method Summary collapse
-
#initialize(source:, target: nil, adjustment_in_sec: 0) ⇒ UserInput
constructor
A new instance of UserInput.
-
#valid? ⇒ Boolean
Validates the source file, if it exists === Valid condition.
- #validate! ⇒ Object
Constructor Details
#initialize(source:, target: nil, adjustment_in_sec: 0) ⇒ UserInput
Returns a new instance of UserInput.
16 17 18 19 20 |
# File 'lib/subjuster/user_input.rb', line 16 def initialize(source:, target: nil, adjustment_in_sec: 0) @source_filepath = File.(source || '') @target_filepath = target && File.(target) || "#{source_filepath}.modified.srt" @adjustment_in_sec = adjustment_in_sec end |
Instance Attribute Details
#adjustment_in_sec ⇒ Object (readonly)
Returns the value of attribute adjustment_in_sec.
15 16 17 |
# File 'lib/subjuster/user_input.rb', line 15 def adjustment_in_sec @adjustment_in_sec end |
#source_filepath ⇒ Object (readonly)
Returns the value of attribute source_filepath.
15 16 17 |
# File 'lib/subjuster/user_input.rb', line 15 def source_filepath @source_filepath end |
#target_filepath ⇒ Object (readonly)
Returns the value of attribute target_filepath.
15 16 17 |
# File 'lib/subjuster/user_input.rb', line 15 def target_filepath @target_filepath end |
Instance Method Details
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/subjuster/user_input.rb', line 34 def valid? File.exist?(source_filepath) end |
#validate! ⇒ Object
38 39 40 |
# File 'lib/subjuster/user_input.rb', line 38 def validate! raise InputError, "Invalid file: #{source_filepath}" unless valid? end |