Class: EndiFeed::CLI
- Inherits:
-
Object
- Object
- EndiFeed::CLI
- Defined in:
- lib/endi_feed/cli.rb
Overview
A Simple class for the executable version of the gem
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
-
#parse ⇒ String
Parses the command-line arguments and runs the executable.
-
#set_options(opts) ⇒ Object
Configures the arguments for the command.
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
10 11 12 |
# File 'lib/endi_feed/cli.rb', line 10 def initialize(args) @args = args end |
Instance Method Details
#parse ⇒ String
Parses the command-line arguments and runs the executable
44 45 46 47 48 |
# File 'lib/endi_feed/cli.rb', line 44 def parse opts = OptionParser.new(&method(:set_options)) opts.parse!(@args) get_news end |
#set_options(opts) ⇒ Object
Configures the arguments for the command
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/endi_feed/cli.rb', line 16 def (opts) @total_news = 25 opts.version = EndiFeed::VERSION opts. = <<MSG Usage: endifeed [options] [arguments] Description: EndiFeed, get the latest news from endi.com / El Nuevo Dia Newspaper. Options: MSG opts.set_program_name 'EndiFeed' opts.on('-n [total]', Integer, '--news', 'total of news to fetch') do |total| @total_news = total end opts.on_tail('-v', '--version', 'display the version of EndiFeed') do puts opts.version exit end opts.on_tail('-h', '--help', 'print this help') do puts opts.help exit end end |