Class: QuickAndRuby::Time::EpochCli
- Inherits:
-
Object
- Object
- QuickAndRuby::Time::EpochCli
- Defined in:
- lib/quick_and_ruby/time/epoch_cli.rb
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#initialize(argv: ARGV, env: ENV) ⇒ EpochCli
constructor
A new instance of EpochCli.
- #parse_options(options: Options.new) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv: ARGV, env: ENV) ⇒ EpochCli
Returns a new instance of EpochCli.
26 27 28 29 |
# File 'lib/quick_and_ruby/time/epoch_cli.rb', line 26 def initialize(argv: ARGV, env: ENV) @argv = argv.clone @env = env.to_h.clone end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
24 25 26 |
# File 'lib/quick_and_ruby/time/epoch_cli.rb', line 24 def argv @argv end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
24 25 26 |
# File 'lib/quick_and_ruby/time/epoch_cli.rb', line 24 def env @env end |
Instance Method Details
#parse_options(options: Options.new) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/quick_and_ruby/time/epoch_cli.rb', line 36 def (options: Options.new) parser = OptionParser.new do |opts| opts. = 'Usage: epoch [options]' opts.on('-h', '--help', 'Prints this help') do puts parser exit end opts.on('-m', '--millis', 'Display epoch in milliseconds') do |_millis| .millis = true end opts.on('-u', '--utc', 'Display time in UTC') do .utc = true end end parser.parse!(argv) end |
#run ⇒ Object
31 32 33 34 |
# File 'lib/quick_and_ruby/time/epoch_cli.rb', line 31 def run = puts EpochConverter.new(**.to_h).convert_all(*argv) end |