Class: Mericope::CLI
- Inherits:
-
Object
- Object
- Mericope::CLI
- Defined in:
- lib/mericope/cli.rb
Constant Summary collapse
- ALLOWED_COMMANDS =
%w{help normalize parse substitute reverse-substitute usage}
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #help ⇒ Object
- #normalize ⇒ Object
- #parse ⇒ Object
- #reverse_substitute ⇒ Object
- #substitute ⇒ Object
- #usage ⇒ Object
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/mericope/cli.rb', line 6 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/mericope/cli.rb', line 6 def @options end |
Class Method Details
.run(command, *args) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/mericope/cli.rb', line 10 def self.run(command, *args) if ALLOWED_COMMANDS.member?(command) command = command.gsub(/-/, '_').to_sym CLI.new(*args).send(command) else CLI.new(*args).usage end end |
Instance Method Details
#help ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mericope/cli.rb', line 19 def help print <<-HELP Glossary pericope A Bible reference (e.g. Romans 3:6-11) mericope A Mormon Pericope verse ID An integer that uniquely identifies a Bible verse HELP end |
#normalize ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/mericope/cli.rb', line 31 def normalize begin mericope = Mericope.new(input) print mericope.to_s rescue print $!.to_s end end |
#parse ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/mericope/cli.rb', line 40 def parse begin mericope = Mericope.new(input) print mericope.to_a.join("\n") rescue print $!.to_s end end |
#reverse_substitute ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/mericope/cli.rb', line 57 def reverse_substitute begin print Mericope.rsub(input) rescue print $!.to_s end end |
#substitute ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/mericope/cli.rb', line 49 def substitute begin print Mericope.sub(input) rescue print $!.to_s end end |
#usage ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mericope/cli.rb', line 65 def usage print <<-USAGE Usage mericope [Command] [Input] Commands help Prints more information about mericope normalize Accepts a mericope and returns a properly-formatted mericope parse Accepts a mericope and returns a list of verse IDs substitute Accepts a block of text and replaces all mericopes in the text with verse IDs reverse-substitute Accepts a block of text and replaces collections of verse IDs with mericopes usage Prints this message USAGE end |