mericope 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cli/base.rb ADDED
@@ -0,0 +1,30 @@
1
+ module CLI
2
+ class Base
3
+
4
+
5
+
6
+ def self.command(name, description, &block)
7
+
8
+ end
9
+
10
+
11
+
12
+ def self.print_commands
13
+ usage = ""
14
+
15
+ end
16
+
17
+
18
+
19
+ private
20
+
21
+
22
+
23
+ def commands
24
+ @commands || {}
25
+ end
26
+
27
+
28
+
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module CLI
2
+ class Command
3
+
4
+
5
+
6
+ def initialize(name, description, &block)
7
+ @name, @description, @block = name, description, &block
8
+ end
9
+
10
+
11
+
12
+ attr_reader :name, :description
13
+
14
+
15
+
16
+ def execute
17
+ @block.call
18
+ end
19
+
20
+
21
+
22
+ end
23
+ end
@@ -0,0 +1,124 @@
1
+ require 'mericope'
2
+ require 'cli/base'
3
+
4
+ class Mericope
5
+ class CLI
6
+
7
+
8
+
9
+ ALLOWED_COMMANDS = %w{help normalize parse substitute reverse-substitute usage}
10
+
11
+
12
+
13
+ def self.run(command, *args)
14
+ if ALLOWED_COMMANDS.member?(command)
15
+ command = command.gsub(/-/, '_').to_sym
16
+ CLI.new(*args).send(command)
17
+ else
18
+ CLI.new(*args).usage
19
+ end
20
+ end
21
+
22
+
23
+
24
+ def help
25
+ print <<-HELP
26
+
27
+ Glossary
28
+
29
+ pericope A Bible reference (e.g. Romans 3:6-11)
30
+ mericope A Mormon Pericope
31
+ verse ID An integer that uniquely identifies a Bible verse
32
+
33
+ HELP
34
+ end
35
+
36
+
37
+
38
+ def normalize
39
+ begin
40
+ mericope = Mericope.new(input)
41
+ print mericope.to_s
42
+ rescue
43
+ print $!.to_s
44
+ end
45
+ end
46
+
47
+
48
+
49
+ def parse
50
+ begin
51
+ mericope = Mericope.new(input)
52
+ print mericope.to_a.join("\n")
53
+ rescue
54
+ print $!.to_s
55
+ end
56
+ end
57
+
58
+
59
+
60
+ def substitute
61
+ begin
62
+ print Mericope.sub(input)
63
+ rescue
64
+ print $!.to_s
65
+ end
66
+ end
67
+
68
+
69
+
70
+ def reverse_substitute
71
+ begin
72
+ print Mericope.rsub(input)
73
+ rescue
74
+ print $!.to_s
75
+ end
76
+ end
77
+
78
+
79
+
80
+ def usage
81
+ print <<-USAGE
82
+
83
+ Usage
84
+
85
+ mericope [Command] [Input]
86
+
87
+ Commands
88
+
89
+ help Prints more information about mericope
90
+ normalize Accepts a mericope and returns a properly-formatted mericope
91
+ parse Accepts a mericope and returns a list of verse IDs
92
+ substitute Accepts a block of text and replaces all mericopes in the text with verse IDs
93
+ reverse-substitute Accepts a block of text and replaces collections of verse IDs with mericopes
94
+ usage Prints this message
95
+
96
+ USAGE
97
+ end
98
+
99
+
100
+
101
+ private
102
+
103
+
104
+
105
+ def initialize(*args)
106
+ @options = extract_options!(*args)
107
+ @input = args.first
108
+ @input = $stdin.read if $stdin.stat.pipe?
109
+ end
110
+
111
+
112
+
113
+ attr_reader :options, :input
114
+
115
+
116
+
117
+ def extract_options!(*args)
118
+ {} # No options accepted yet
119
+ end
120
+
121
+
122
+
123
+ end
124
+ end
@@ -0,0 +1,3 @@
1
+ class Mericope
2
+ VERSION = "0.1.0" unless defined?(::Mericope::Version)
3
+ end