wcc-pericope 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.mdown +70 -0
- data/bin/console +14 -0
- data/bin/pericope +9 -0
- data/data/chapter_verse_count.txt +1189 -0
- data/lib/cli/base.rb +18 -0
- data/lib/cli/command.rb +15 -0
- data/lib/pericope/cli.rb +87 -0
- data/lib/pericope/data.rb +4 -0
- data/lib/pericope/parsing.rb +289 -0
- data/lib/pericope/range.rb +58 -0
- data/lib/pericope/verse.rb +75 -0
- data/lib/pericope/version.rb +3 -0
- data/lib/pericope.rb +247 -0
- metadata +171 -0
data/lib/cli/base.rb
ADDED
data/lib/cli/command.rb
ADDED
data/lib/pericope/cli.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require "pericope"
|
2
|
+
require "cli/base"
|
3
|
+
|
4
|
+
class Pericope
|
5
|
+
class CLI
|
6
|
+
|
7
|
+
ALLOWED_COMMANDS = %w{help normalize parse usage}
|
8
|
+
|
9
|
+
def self.run(command, *args)
|
10
|
+
if ALLOWED_COMMANDS.member?(command)
|
11
|
+
command = command.gsub(/-/, '_').to_sym
|
12
|
+
CLI.new(*args).send(command)
|
13
|
+
else
|
14
|
+
CLI.new(*args).usage
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def help
|
21
|
+
print <<-HELP
|
22
|
+
|
23
|
+
Glossary
|
24
|
+
|
25
|
+
pericope A Bible reference (e.g. Romans 3:6-11)
|
26
|
+
verse ID An integer that uniquely identifies a Bible verse
|
27
|
+
|
28
|
+
HELP
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def normalize
|
34
|
+
begin
|
35
|
+
pericope = Pericope.new(input)
|
36
|
+
print pericope.to_s
|
37
|
+
rescue
|
38
|
+
print $!.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
def parse
|
45
|
+
begin
|
46
|
+
pericope = Pericope.new(input)
|
47
|
+
print pericope.to_a.join("\n")
|
48
|
+
rescue
|
49
|
+
print $!.to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def usage
|
56
|
+
print <<-USAGE
|
57
|
+
|
58
|
+
Usage
|
59
|
+
|
60
|
+
pericope [Command] [Input]
|
61
|
+
|
62
|
+
Commands
|
63
|
+
|
64
|
+
help Prints more information about pericope
|
65
|
+
normalize Accepts a pericope and returns a properly-formatted pericope
|
66
|
+
parse Accepts a pericope and returns a list of verse IDs
|
67
|
+
usage Prints this message
|
68
|
+
|
69
|
+
USAGE
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
private
|
75
|
+
attr_reader :options, :input
|
76
|
+
|
77
|
+
def initialize(*args)
|
78
|
+
@options = extract_options!(*args)
|
79
|
+
@input = args.first
|
80
|
+
@input = $stdin.read if $stdin.stat.pipe?
|
81
|
+
end
|
82
|
+
|
83
|
+
def extract_options!(*args)
|
84
|
+
{} # No options accepted yet
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
class Pericope
|
2
|
+
CHAPTER_VERSE_COUNTS = {1001000=>31, 1002000=>25, 1003000=>24, 1004000=>26, 1005000=>32, 1006000=>22, 1007000=>24, 1008000=>22, 1009000=>29, 1010000=>32, 1011000=>32, 1012000=>20, 1013000=>18, 1014000=>24, 1015000=>21, 1016000=>16, 1017000=>27, 1018000=>33, 1019000=>38, 1020000=>18, 1021000=>34, 1022000=>24, 1023000=>20, 1024000=>67, 1025000=>34, 1026000=>35, 1027000=>46, 1028000=>22, 1029000=>35, 1030000=>43, 1031000=>55, 1032000=>32, 1033000=>20, 1034000=>31, 1035000=>29, 1036000=>43, 1037000=>36, 1038000=>30, 1039000=>23, 1040000=>23, 1041000=>57, 1042000=>38, 1043000=>34, 1044000=>34, 1045000=>28, 1046000=>34, 1047000=>31, 1048000=>22, 1049000=>33, 1050000=>26, 2001000=>22, 2002000=>25, 2003000=>22, 2004000=>31, 2005000=>23, 2006000=>30, 2007000=>25, 2008000=>32, 2009000=>35, 2010000=>29, 2011000=>10, 2012000=>51, 2013000=>22, 2014000=>31, 2015000=>27, 2016000=>36, 2017000=>16, 2018000=>27, 2019000=>25, 2020000=>26, 2021000=>36, 2022000=>31, 2023000=>33, 2024000=>18, 2025000=>40, 2026000=>37, 2027000=>21, 2028000=>43, 2029000=>46, 2030000=>38, 2031000=>18, 2032000=>35, 2033000=>23, 2034000=>35, 2035000=>35, 2036000=>38, 2037000=>29, 2038000=>31, 2039000=>43, 2040000=>38, 3001000=>17, 3002000=>16, 3003000=>17, 3004000=>35, 3005000=>19, 3006000=>30, 3007000=>38, 3008000=>36, 3009000=>24, 3010000=>20, 3011000=>47, 3012000=>8, 3013000=>59, 3014000=>57, 3015000=>33, 3016000=>34, 3017000=>16, 3018000=>30, 3019000=>37, 3020000=>27, 3021000=>24, 3022000=>33, 3023000=>44, 3024000=>23, 3025000=>55, 3026000=>46, 3027000=>34, 4001000=>54, 4002000=>34, 4003000=>51, 4004000=>49, 4005000=>31, 4006000=>27, 4007000=>89, 4008000=>26, 4009000=>23, 4010000=>36, 4011000=>35, 4012000=>16, 4013000=>33, 4014000=>45, 4015000=>41, 4016000=>50, 4017000=>13, 4018000=>32, 4019000=>22, 4020000=>29, 4021000=>35, 4022000=>41, 4023000=>30, 4024000=>25, 4025000=>18, 4026000=>65, 4027000=>23, 4028000=>31, 4029000=>40, 4030000=>16, 4031000=>54, 4032000=>42, 4033000=>56, 4034000=>29, 4035000=>34, 4036000=>13, 5001000=>46, 5002000=>37, 5003000=>29, 5004000=>49, 5005000=>33, 5006000=>25, 5007000=>26, 5008000=>20, 5009000=>29, 5010000=>22, 5011000=>32, 5012000=>32, 5013000=>18, 5014000=>29, 5015000=>23, 5016000=>22, 5017000=>20, 5018000=>22, 5019000=>21, 5020000=>20, 5021000=>23, 5022000=>30, 5023000=>25, 5024000=>22, 5025000=>19, 5026000=>19, 5027000=>26, 5028000=>68, 5029000=>29, 5030000=>20, 5031000=>30, 5032000=>52, 5033000=>29, 5034000=>12, 6001000=>18, 6002000=>24, 6003000=>17, 6004000=>24, 6005000=>15, 6006000=>27, 6007000=>26, 6008000=>35, 6009000=>27, 6010000=>43, 6011000=>23, 6012000=>24, 6013000=>33, 6014000=>15, 6015000=>63, 6016000=>10, 6017000=>18, 6018000=>28, 6019000=>51, 6020000=>9, 6021000=>45, 6022000=>34, 6023000=>16, 6024000=>33, 7001000=>36, 7002000=>23, 7003000=>31, 7004000=>24, 7005000=>31, 7006000=>40, 7007000=>25, 7008000=>35, 7009000=>57, 7010000=>18, 7011000=>40, 7012000=>15, 7013000=>25, 7014000=>20, 7015000=>20, 7016000=>31, 7017000=>13, 7018000=>31, 7019000=>30, 7020000=>48, 7021000=>25, 8001000=>22, 8002000=>23, 8003000=>18, 8004000=>22, 9001000=>28, 9002000=>36, 9003000=>21, 9004000=>22, 9005000=>12, 9006000=>21, 9007000=>17, 9008000=>22, 9009000=>27, 9010000=>27, 9011000=>15, 9012000=>25, 9013000=>23, 9014000=>52, 9015000=>35, 9016000=>23, 9017000=>58, 9018000=>30, 9019000=>24, 9020000=>42, 9021000=>15, 9022000=>23, 9023000=>29, 9024000=>22, 9025000=>44, 9026000=>25, 9027000=>12, 9028000=>25, 9029000=>11, 9030000=>31, 9031000=>13, 10001000=>27, 10002000=>32, 10003000=>39, 10004000=>12, 10005000=>25, 10006000=>23, 10007000=>29, 10008000=>18, 10009000=>13, 10010000=>19, 10011000=>27, 10012000=>31, 10013000=>39, 10014000=>33, 10015000=>37, 10016000=>23, 10017000=>29, 10018000=>33, 10019000=>43, 10020000=>26, 10021000=>22, 10022000=>51, 10023000=>39, 10024000=>25, 11001000=>53, 11002000=>46, 11003000=>28, 11004000=>34, 11005000=>18, 11006000=>38, 11007000=>51, 11008000=>66, 11009000=>28, 11010000=>29, 11011000=>43, 11012000=>33, 11013000=>34, 11014000=>31, 11015000=>34, 11016000=>34, 11017000=>24, 11018000=>46, 11019000=>21, 11020000=>43, 11021000=>29, 11022000=>53, 12001000=>18, 12002000=>25, 12003000=>27, 12004000=>44, 12005000=>27, 12006000=>33, 12007000=>20, 12008000=>29, 12009000=>37, 12010000=>36, 12011000=>21, 12012000=>21, 12013000=>25, 12014000=>29, 12015000=>38, 12016000=>20, 12017000=>41, 12018000=>37, 12019000=>37, 12020000=>21, 12021000=>26, 12022000=>20, 12023000=>37, 12024000=>20, 12025000=>30, 13001000=>54, 13002000=>55, 13003000=>24, 13004000=>43, 13005000=>26, 13006000=>81, 13007000=>40, 13008000=>40, 13009000=>44, 13010000=>14, 13011000=>47, 13012000=>40, 13013000=>14, 13014000=>17, 13015000=>29, 13016000=>43, 13017000=>27, 13018000=>17, 13019000=>19, 13020000=>8, 13021000=>30, 13022000=>19, 13023000=>32, 13024000=>31, 13025000=>31, 13026000=>32, 13027000=>34, 13028000=>21, 13029000=>30, 14001000=>17, 14002000=>18, 14003000=>17, 14004000=>22, 14005000=>14, 14006000=>42, 14007000=>22, 14008000=>18, 14009000=>31, 14010000=>19, 14011000=>23, 14012000=>16, 14013000=>22, 14014000=>15, 14015000=>19, 14016000=>14, 14017000=>19, 14018000=>34, 14019000=>11, 14020000=>37, 14021000=>20, 14022000=>12, 14023000=>21, 14024000=>27, 14025000=>28, 14026000=>23, 14027000=>9, 14028000=>27, 14029000=>36, 14030000=>27, 14031000=>21, 14032000=>33, 14033000=>25, 14034000=>33, 14035000=>27, 14036000=>23, 15001000=>11, 15002000=>70, 15003000=>13, 15004000=>24, 15005000=>17, 15006000=>22, 15007000=>28, 15008000=>36, 15009000=>15, 15010000=>44, 16001000=>11, 16002000=>20, 16003000=>32, 16004000=>23, 16005000=>19, 16006000=>19, 16007000=>73, 16008000=>18, 16009000=>38, 16010000=>39, 16011000=>36, 16012000=>47, 16013000=>31, 17001000=>22, 17002000=>23, 17003000=>15, 17004000=>17, 17005000=>14, 17006000=>14, 17007000=>10, 17008000=>17, 17009000=>32, 17010000=>3, 18001000=>22, 18002000=>13, 18003000=>26, 18004000=>21, 18005000=>27, 18006000=>30, 18007000=>21, 18008000=>22, 18009000=>35, 18010000=>22, 18011000=>20, 18012000=>25, 18013000=>28, 18014000=>22, 18015000=>35, 18016000=>22, 18017000=>16, 18018000=>21, 18019000=>29, 18020000=>29, 18021000=>34, 18022000=>30, 18023000=>17, 18024000=>25, 18025000=>6, 18026000=>14, 18027000=>23, 18028000=>28, 18029000=>25, 18030000=>31, 18031000=>40, 18032000=>22, 18033000=>33, 18034000=>37, 18035000=>16, 18036000=>33, 18037000=>24, 18038000=>41, 18039000=>30, 18040000=>24, 18041000=>34, 18042000=>17, 19001000=>6, 19002000=>12, 19003000=>8, 19004000=>8, 19005000=>12, 19006000=>10, 19007000=>17, 19008000=>9, 19009000=>20, 19010000=>18, 19011000=>7, 19012000=>8, 19013000=>6, 19014000=>7, 19015000=>5, 19016000=>11, 19017000=>15, 19018000=>50, 19019000=>14, 19020000=>9, 19021000=>13, 19022000=>31, 19023000=>6, 19024000=>10, 19025000=>22, 19026000=>12, 19027000=>14, 19028000=>9, 19029000=>11, 19030000=>12, 19031000=>24, 19032000=>11, 19033000=>22, 19034000=>22, 19035000=>28, 19036000=>12, 19037000=>40, 19038000=>22, 19039000=>13, 19040000=>17, 19041000=>13, 19042000=>11, 19043000=>5, 19044000=>26, 19045000=>17, 19046000=>11, 19047000=>9, 19048000=>14, 19049000=>20, 19050000=>23, 19051000=>19, 19052000=>9, 19053000=>6, 19054000=>7, 19055000=>23, 19056000=>13, 19057000=>11, 19058000=>11, 19059000=>17, 19060000=>12, 19061000=>8, 19062000=>12, 19063000=>11, 19064000=>10, 19065000=>13, 19066000=>20, 19067000=>7, 19068000=>35, 19069000=>36, 19070000=>5, 19071000=>24, 19072000=>20, 19073000=>28, 19074000=>23, 19075000=>10, 19076000=>12, 19077000=>20, 19078000=>72, 19079000=>13, 19080000=>19, 19081000=>16, 19082000=>8, 19083000=>18, 19084000=>12, 19085000=>13, 19086000=>17, 19087000=>7, 19088000=>18, 19089000=>52, 19090000=>17, 19091000=>16, 19092000=>15, 19093000=>5, 19094000=>23, 19095000=>11, 19096000=>13, 19097000=>12, 19098000=>9, 19099000=>9, 19100000=>5, 19101000=>8, 19102000=>28, 19103000=>22, 19104000=>35, 19105000=>45, 19106000=>48, 19107000=>43, 19108000=>13, 19109000=>31, 19110000=>7, 19111000=>10, 19112000=>10, 19113000=>9, 19114000=>8, 19115000=>18, 19116000=>19, 19117000=>2, 19118000=>29, 19119000=>176, 19120000=>7, 19121000=>8, 19122000=>9, 19123000=>4, 19124000=>8, 19125000=>5, 19126000=>6, 19127000=>5, 19128000=>6, 19129000=>8, 19130000=>8, 19131000=>3, 19132000=>18, 19133000=>3, 19134000=>3, 19135000=>21, 19136000=>26, 19137000=>9, 19138000=>8, 19139000=>24, 19140000=>13, 19141000=>10, 19142000=>7, 19143000=>12, 19144000=>15, 19145000=>21, 19146000=>10, 19147000=>20, 19148000=>14, 19149000=>9, 19150000=>6, 20001000=>33, 20002000=>22, 20003000=>35, 20004000=>27, 20005000=>23, 20006000=>35, 20007000=>27, 20008000=>36, 20009000=>18, 20010000=>32, 20011000=>31, 20012000=>28, 20013000=>25, 20014000=>35, 20015000=>33, 20016000=>33, 20017000=>28, 20018000=>24, 20019000=>29, 20020000=>30, 20021000=>31, 20022000=>29, 20023000=>35, 20024000=>34, 20025000=>28, 20026000=>28, 20027000=>27, 20028000=>28, 20029000=>27, 20030000=>33, 20031000=>31, 21001000=>18, 21002000=>26, 21003000=>22, 21004000=>16, 21005000=>20, 21006000=>12, 21007000=>29, 21008000=>17, 21009000=>18, 21010000=>20, 21011000=>10, 21012000=>14, 22001000=>17, 22002000=>17, 22003000=>11, 22004000=>16, 22005000=>16, 22006000=>13, 22007000=>13, 22008000=>14, 23001000=>31, 23002000=>22, 23003000=>26, 23004000=>6, 23005000=>30, 23006000=>13, 23007000=>25, 23008000=>22, 23009000=>21, 23010000=>34, 23011000=>16, 23012000=>6, 23013000=>22, 23014000=>32, 23015000=>9, 23016000=>14, 23017000=>14, 23018000=>7, 23019000=>25, 23020000=>6, 23021000=>17, 23022000=>25, 23023000=>18, 23024000=>23, 23025000=>12, 23026000=>21, 23027000=>13, 23028000=>29, 23029000=>24, 23030000=>33, 23031000=>9, 23032000=>20, 23033000=>24, 23034000=>17, 23035000=>10, 23036000=>22, 23037000=>38, 23038000=>22, 23039000=>8, 23040000=>31, 23041000=>29, 23042000=>25, 23043000=>28, 23044000=>28, 23045000=>25, 23046000=>13, 23047000=>15, 23048000=>22, 23049000=>26, 23050000=>11, 23051000=>23, 23052000=>15, 23053000=>12, 23054000=>17, 23055000=>13, 23056000=>12, 23057000=>21, 23058000=>14, 23059000=>21, 23060000=>22, 23061000=>11, 23062000=>12, 23063000=>19, 23064000=>12, 23065000=>25, 23066000=>24, 24001000=>19, 24002000=>37, 24003000=>25, 24004000=>31, 24005000=>31, 24006000=>30, 24007000=>34, 24008000=>22, 24009000=>26, 24010000=>25, 24011000=>23, 24012000=>17, 24013000=>27, 24014000=>22, 24015000=>21, 24016000=>21, 24017000=>27, 24018000=>23, 24019000=>15, 24020000=>18, 24021000=>14, 24022000=>30, 24023000=>40, 24024000=>10, 24025000=>38, 24026000=>24, 24027000=>22, 24028000=>17, 24029000=>32, 24030000=>24, 24031000=>40, 24032000=>44, 24033000=>26, 24034000=>22, 24035000=>19, 24036000=>32, 24037000=>21, 24038000=>28, 24039000=>18, 24040000=>16, 24041000=>18, 24042000=>22, 24043000=>13, 24044000=>30, 24045000=>5, 24046000=>28, 24047000=>7, 24048000=>47, 24049000=>39, 24050000=>46, 24051000=>64, 24052000=>34, 25001000=>22, 25002000=>22, 25003000=>66, 25004000=>22, 25005000=>22, 26001000=>28, 26002000=>10, 26003000=>27, 26004000=>17, 26005000=>17, 26006000=>14, 26007000=>27, 26008000=>18, 26009000=>11, 26010000=>22, 26011000=>25, 26012000=>28, 26013000=>23, 26014000=>23, 26015000=>8, 26016000=>63, 26017000=>24, 26018000=>32, 26019000=>14, 26020000=>49, 26021000=>32, 26022000=>31, 26023000=>49, 26024000=>27, 26025000=>17, 26026000=>21, 26027000=>36, 26028000=>26, 26029000=>21, 26030000=>26, 26031000=>18, 26032000=>32, 26033000=>33, 26034000=>31, 26035000=>15, 26036000=>38, 26037000=>28, 26038000=>23, 26039000=>29, 26040000=>49, 26041000=>26, 26042000=>20, 26043000=>27, 26044000=>31, 26045000=>25, 26046000=>24, 26047000=>23, 26048000=>35, 27001000=>21, 27002000=>49, 27003000=>30, 27004000=>37, 27005000=>31, 27006000=>28, 27007000=>28, 27008000=>27, 27009000=>27, 27010000=>21, 27011000=>45, 27012000=>13, 28001000=>11, 28002000=>23, 28003000=>5, 28004000=>19, 28005000=>15, 28006000=>11, 28007000=>16, 28008000=>14, 28009000=>17, 28010000=>15, 28011000=>12, 28012000=>14, 28013000=>16, 28014000=>9, 29001000=>20, 29002000=>32, 29003000=>21, 30001000=>15, 30002000=>16, 30003000=>15, 30004000=>13, 30005000=>27, 30006000=>14, 30007000=>17, 30008000=>14, 30009000=>15, 31001000=>21, 32001000=>17, 32002000=>10, 32003000=>10, 32004000=>11, 33001000=>16, 33002000=>13, 33003000=>12, 33004000=>13, 33005000=>15, 33006000=>16, 33007000=>20, 34001000=>15, 34002000=>13, 34003000=>19, 35001000=>17, 35002000=>20, 35003000=>19, 36001000=>18, 36002000=>15, 36003000=>20, 37001000=>15, 37002000=>23, 38001000=>21, 38002000=>13, 38003000=>10, 38004000=>14, 38005000=>11, 38006000=>15, 38007000=>14, 38008000=>23, 38009000=>17, 38010000=>12, 38011000=>17, 38012000=>14, 38013000=>9, 38014000=>21, 39001000=>14, 39002000=>17, 39003000=>18, 39004000=>6, 40001000=>25, 40002000=>23, 40003000=>17, 40004000=>25, 40005000=>48, 40006000=>34, 40007000=>29, 40008000=>34, 40009000=>38, 40010000=>42, 40011000=>30, 40012000=>50, 40013000=>58, 40014000=>36, 40015000=>39, 40016000=>28, 40017000=>27, 40018000=>35, 40019000=>30, 40020000=>34, 40021000=>46, 40022000=>46, 40023000=>39, 40024000=>51, 40025000=>46, 40026000=>75, 40027000=>66, 40028000=>20, 41001000=>45, 41002000=>28, 41003000=>35, 41004000=>41, 41005000=>43, 41006000=>56, 41007000=>37, 41008000=>38, 41009000=>50, 41010000=>52, 41011000=>33, 41012000=>44, 41013000=>37, 41014000=>72, 41015000=>47, 41016000=>20, 42001000=>80, 42002000=>52, 42003000=>38, 42004000=>44, 42005000=>39, 42006000=>49, 42007000=>50, 42008000=>56, 42009000=>62, 42010000=>42, 42011000=>54, 42012000=>59, 42013000=>35, 42014000=>35, 42015000=>32, 42016000=>31, 42017000=>37, 42018000=>43, 42019000=>48, 42020000=>47, 42021000=>38, 42022000=>71, 42023000=>56, 42024000=>53, 43001000=>51, 43002000=>25, 43003000=>36, 43004000=>54, 43005000=>47, 43006000=>71, 43007000=>53, 43008000=>59, 43009000=>41, 43010000=>42, 43011000=>57, 43012000=>50, 43013000=>38, 43014000=>31, 43015000=>27, 43016000=>33, 43017000=>26, 43018000=>40, 43019000=>42, 43020000=>31, 43021000=>25, 44001000=>26, 44002000=>47, 44003000=>26, 44004000=>37, 44005000=>42, 44006000=>15, 44007000=>60, 44008000=>40, 44009000=>43, 44010000=>48, 44011000=>30, 44012000=>25, 44013000=>52, 44014000=>28, 44015000=>41, 44016000=>40, 44017000=>34, 44018000=>28, 44019000=>41, 44020000=>38, 44021000=>40, 44022000=>30, 44023000=>35, 44024000=>27, 44025000=>27, 44026000=>32, 44027000=>44, 44028000=>31, 45001000=>32, 45002000=>29, 45003000=>31, 45004000=>25, 45005000=>21, 45006000=>23, 45007000=>25, 45008000=>39, 45009000=>33, 45010000=>21, 45011000=>36, 45012000=>21, 45013000=>14, 45014000=>23, 45015000=>33, 45016000=>27, 46001000=>31, 46002000=>16, 46003000=>23, 46004000=>21, 46005000=>13, 46006000=>20, 46007000=>40, 46008000=>13, 46009000=>27, 46010000=>33, 46011000=>34, 46012000=>31, 46013000=>13, 46014000=>40, 46015000=>58, 46016000=>24, 47001000=>24, 47002000=>17, 47003000=>18, 47004000=>18, 47005000=>21, 47006000=>18, 47007000=>16, 47008000=>24, 47009000=>15, 47010000=>18, 47011000=>33, 47012000=>21, 47013000=>14, 48001000=>24, 48002000=>21, 48003000=>29, 48004000=>31, 48005000=>26, 48006000=>18, 49001000=>23, 49002000=>22, 49003000=>21, 49004000=>32, 49005000=>33, 49006000=>24, 50001000=>30, 50002000=>30, 50003000=>21, 50004000=>23, 51001000=>29, 51002000=>23, 51003000=>25, 51004000=>18, 52001000=>10, 52002000=>20, 52003000=>13, 52004000=>18, 52005000=>28, 53001000=>12, 53002000=>17, 53003000=>18, 54001000=>20, 54002000=>15, 54003000=>16, 54004000=>16, 54005000=>25, 54006000=>21, 55001000=>18, 55002000=>26, 55003000=>17, 55004000=>22, 56001000=>16, 56002000=>15, 56003000=>15, 57001000=>25, 58001000=>14, 58002000=>18, 58003000=>19, 58004000=>16, 58005000=>14, 58006000=>20, 58007000=>28, 58008000=>13, 58009000=>28, 58010000=>39, 58011000=>40, 58012000=>29, 58013000=>25, 59001000=>27, 59002000=>26, 59003000=>18, 59004000=>17, 59005000=>20, 60001000=>25, 60002000=>25, 60003000=>22, 60004000=>19, 60005000=>14, 61001000=>21, 61002000=>22, 61003000=>18, 62001000=>10, 62002000=>29, 62003000=>24, 62004000=>21, 62005000=>21, 63001000=>13, 64001000=>15, 65001000=>25, 66001000=>20, 66002000=>29, 66003000=>22, 66004000=>11, 66005000=>14, 66006000=>17, 66007000=>17, 66008000=>13, 66009000=>21, 66010000=>11, 66011000=>19, 66012000=>17, 66013000=>18, 66014000=>20, 66015000=>8, 66016000=>21, 66017000=>18, 66018000=>24, 66019000=>21, 66020000=>15, 66021000=>27, 66022000=>21}.freeze
|
3
|
+
BOOK_CHAPTER_COUNTS = [nil, 50, 40, 27, 36, 34, 24, 21, 4, 31, 24, 22, 25, 29, 36, 10, 13, 10, 42, 150, 31, 12, 8, 66, 52, 5, 48, 12, 14, 3, 9, 1, 4, 7, 3, 3, 3, 2, 14, 4, 28, 16, 24, 21, 28, 16, 16, 13, 6, 6, 4, 4, 5, 3, 6, 4, 3, 1, 13, 5, 5, 3, 5, 1, 1, 1, 22].freeze
|
4
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require "pericope/range"
|
2
|
+
require "pericope/verse"
|
3
|
+
|
4
|
+
class Pericope
|
5
|
+
module Parsing
|
6
|
+
|
7
|
+
# Differs from Pericope.new in that it won't raise an exception
|
8
|
+
# if text does not contain a pericope but will return nil instead.
|
9
|
+
def parse_one(text)
|
10
|
+
parse(text) do |pericope|
|
11
|
+
return pericope
|
12
|
+
end
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(text)
|
17
|
+
pericopes = []
|
18
|
+
match_all(text) do |attributes|
|
19
|
+
pericope = Pericope.new(attributes)
|
20
|
+
if block_given?
|
21
|
+
yield pericope
|
22
|
+
else
|
23
|
+
pericopes << pericope
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
match_book(text) do |attributes|
|
28
|
+
pericope = Pericope.new(attributes)
|
29
|
+
if block_given?
|
30
|
+
yield pericope
|
31
|
+
else
|
32
|
+
pericopes << pericope
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
block_given? ? text : pericopes
|
37
|
+
end
|
38
|
+
|
39
|
+
def split(text)
|
40
|
+
segments = []
|
41
|
+
start = 0
|
42
|
+
|
43
|
+
match_all(text) do |attributes, match|
|
44
|
+
|
45
|
+
pretext = text.slice(start...match.begin(0))
|
46
|
+
if pretext.length > 0
|
47
|
+
segments << pretext
|
48
|
+
yield pretext if block_given?
|
49
|
+
end
|
50
|
+
|
51
|
+
pericope = Pericope.new(attributes)
|
52
|
+
segments << pericope
|
53
|
+
yield pericope if block_given?
|
54
|
+
|
55
|
+
start = match.end(0)
|
56
|
+
end
|
57
|
+
|
58
|
+
pretext = text.slice(start...text.length)
|
59
|
+
if pretext.length > 0
|
60
|
+
segments << pretext
|
61
|
+
yield pretext if block_given?
|
62
|
+
end
|
63
|
+
|
64
|
+
segments
|
65
|
+
end
|
66
|
+
|
67
|
+
def match_one(text)
|
68
|
+
match_all(text) do |attributes|
|
69
|
+
return attributes
|
70
|
+
end
|
71
|
+
|
72
|
+
match_book(text) do |attributes|
|
73
|
+
return attributes
|
74
|
+
end
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def match_all(text)
|
79
|
+
text.scan(Pericope.regexp) do
|
80
|
+
match = Regexp.last_match
|
81
|
+
book = BOOK_IDS[match.captures.find_index(&:itself)]
|
82
|
+
|
83
|
+
ranges = parse_reference(book, match[67])
|
84
|
+
next if ranges.empty?
|
85
|
+
|
86
|
+
attributes = {
|
87
|
+
:original_string => match.to_s,
|
88
|
+
:book => book,
|
89
|
+
:ranges => ranges
|
90
|
+
}
|
91
|
+
|
92
|
+
yield attributes, match
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def match_book(text)
|
97
|
+
text.scan(Pericope.book_regexp) do
|
98
|
+
match = Regexp.last_match
|
99
|
+
book = BOOK_IDS[match.captures.find_index(&:itself)]
|
100
|
+
attributes = {
|
101
|
+
:original_string => match.to_s,
|
102
|
+
:book => book,
|
103
|
+
:ranges => ''
|
104
|
+
}
|
105
|
+
yield attributes, match
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def parse_reference(book, reference)
|
110
|
+
parse_ranges(book, normalize_reference(reference).split(/[,;]/))
|
111
|
+
end
|
112
|
+
|
113
|
+
def normalize_reference(reference)
|
114
|
+
normalizations.reduce(reference.to_s) { |reference, (regex, replacement)| reference.gsub(regex, replacement) }
|
115
|
+
end
|
116
|
+
|
117
|
+
def parse_ranges(book, ranges)
|
118
|
+
default_chapter = nil
|
119
|
+
default_chapter = 1 unless book_has_chapters?(book)
|
120
|
+
default_verse = nil
|
121
|
+
|
122
|
+
ranges.map do |range|
|
123
|
+
range_begin_string, range_end_string = range.split("-")
|
124
|
+
|
125
|
+
# treat 12:4 as 12:4-12:4
|
126
|
+
range_end_string ||= range_begin_string
|
127
|
+
|
128
|
+
range_begin = parse_reference_fragment(range_begin_string, default_chapter: default_chapter, default_verse: default_verse)
|
129
|
+
|
130
|
+
# no verse specified; this is a range of chapters, start with verse 1
|
131
|
+
chapter_range = false
|
132
|
+
if range_begin.needs_verse?
|
133
|
+
range_begin.verse = 1
|
134
|
+
chapter_range = true
|
135
|
+
end
|
136
|
+
|
137
|
+
range_begin.chapter = to_valid_chapter(book, range_begin.chapter)
|
138
|
+
range_begin.verse = to_valid_verse(book, range_begin.chapter, range_begin.verse)
|
139
|
+
|
140
|
+
if range_begin_string == range_end_string && !chapter_range
|
141
|
+
range_end = range_begin.dup
|
142
|
+
else
|
143
|
+
range_end = parse_reference_fragment(range_end_string, default_chapter: (range_begin.chapter unless chapter_range))
|
144
|
+
range_end.chapter = to_valid_chapter(book, range_end.chapter)
|
145
|
+
|
146
|
+
# treat Mark 3-1 as Mark 3-3 and, eventually, Mark 3:1-35
|
147
|
+
range_end.chapter = range_begin.chapter if range_end.chapter < range_begin.chapter
|
148
|
+
|
149
|
+
# this is a range of chapters, end with the last verse
|
150
|
+
if range_end.needs_verse?
|
151
|
+
range_end.verse = get_max_verse(book, range_end.chapter)
|
152
|
+
else
|
153
|
+
range_end.verse = to_valid_verse(book, range_end.chapter, range_end.verse)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# e.g. parsing 11 in 12:1-8,11 => remember that 12 is the chapter
|
158
|
+
default_chapter = range_end.chapter
|
159
|
+
|
160
|
+
# e.g. parsing c in 9:12a, c => remember that 12 is the verse
|
161
|
+
default_verse = range_end.verse
|
162
|
+
|
163
|
+
range = Range.new(range_begin.to_verse(book: book), range_end.to_verse(book: book))
|
164
|
+
|
165
|
+
# an 'a' at the beginning of a range is redundant
|
166
|
+
range.begin.letter = nil if range.begin.letter == "a" && range.end.to_i > range.begin.to_i
|
167
|
+
|
168
|
+
# a 'c' at the end of a range is redundant
|
169
|
+
range.end.letter = nil if range.end.letter == max_letter && range.end.to_i > range.begin.to_i
|
170
|
+
|
171
|
+
range
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def parse_reference_fragment(input, default_chapter: nil, default_verse: nil)
|
176
|
+
chapter, verse, letter = input.match(Pericope.fragment_regexp).captures
|
177
|
+
chapter = default_chapter unless chapter
|
178
|
+
chapter, verse = [verse, nil] unless chapter
|
179
|
+
verse = default_verse unless verse
|
180
|
+
letter = nil unless verse
|
181
|
+
ReferenceFragment.new(chapter.to_i, verse&.to_i, letter)
|
182
|
+
end
|
183
|
+
|
184
|
+
def to_valid_chapter(book, chapter)
|
185
|
+
coerce_to_range(chapter, 1..get_max_chapter(book))
|
186
|
+
end
|
187
|
+
|
188
|
+
def to_valid_verse(book, chapter, verse)
|
189
|
+
coerce_to_range(verse, 1..get_max_verse(book, chapter))
|
190
|
+
end
|
191
|
+
|
192
|
+
def coerce_to_range(number, range)
|
193
|
+
return range.begin if number < range.begin
|
194
|
+
return range.end if number > range.end
|
195
|
+
number
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
ReferenceFragment = Struct.new(:chapter, :verse, :letter) do
|
200
|
+
def needs_verse?
|
201
|
+
verse.nil?
|
202
|
+
end
|
203
|
+
|
204
|
+
def to_verse(book:)
|
205
|
+
Verse.new(book, chapter, verse, letter)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
BOOK_PATTERN = %r{\b(?:
|
211
|
+
(?:(?:3|iii|third|3rd)\s*(?:
|
212
|
+
(john|joh|jon|jhn|jh|jo|jn)
|
213
|
+
))|
|
214
|
+
(?:(?:2|ii|second|2nd)\s*(?:
|
215
|
+
(samuels|samuel|sam|sa|sm)|
|
216
|
+
(kings|king|kngs|kgs|kg|k)|
|
217
|
+
(chronicles|chronicle|chron|chrn|chr)|
|
218
|
+
(john|joh|jon|jhn|jh|jo|jn)|
|
219
|
+
(corinthians?|cor?|corint?h?|corth)|
|
220
|
+
(thessalonians?|thes{1,}|the?s?)|
|
221
|
+
(timothy|tim|tm|ti)|
|
222
|
+
(peter|pete|pet|ptr|pe|pt|pr)
|
223
|
+
))|
|
224
|
+
(?:(?:1|i|first|1st)\s*(?:
|
225
|
+
(samuels|samuel|sam|sa|sm)|
|
226
|
+
(kings|king|kngs|kgs|kg|k)|
|
227
|
+
(chronicles|chronicle|chron|chrn|chr)|
|
228
|
+
(john|joh|jon|jhn|jh|jo|jn)|
|
229
|
+
(corinthians?|cor?|corint?h?|corth)|
|
230
|
+
(thessalonians?|thes{1,}|the?s?)|
|
231
|
+
(timothy|tim|tm|ti)|
|
232
|
+
(peter|pete|pet|ptr|pe|pt|pr)
|
233
|
+
))|
|
234
|
+
(genesis|gen|gn|ge)|
|
235
|
+
(exodus|exod|exo|exd|ex)|
|
236
|
+
(leviticus|lev|levi|le|lv)|
|
237
|
+
(numbers|number|numb|num|nmb|nu|nm)|
|
238
|
+
(deuteronomy|deut|deu|dt)|
|
239
|
+
(joshua|josh|jsh|jos)|
|
240
|
+
(judges|jdgs|judg|jdg)|
|
241
|
+
(ruth|rut|rth|ru)|
|
242
|
+
(isaiah|isa|is|ia|isai|isah)|
|
243
|
+
(ezra|ezr)|
|
244
|
+
(nehemiah|neh|ne)|
|
245
|
+
(esther|esth|est|es)|
|
246
|
+
(job|jb)|
|
247
|
+
(psalms|psalm|pslms|pslm|psm|psa|ps)|
|
248
|
+
(proverbs|proverb|prov|prv|prvb|prvbs|pv)|
|
249
|
+
(ecclesiastes|eccles|eccl|ecc|ecl)|
|
250
|
+
((?:the\s?)?song\s?of\s?solomon|(?:the\s?)?song\s?of\s?songs|sn?gs?|songs?|so?s|sol?|son|s\s?of\s?\ss)|
|
251
|
+
(jeremiah?|jer?|jr|jere)|
|
252
|
+
(lamentations?|lam?|lm)|
|
253
|
+
(ezekiel|ezek|eze|ezk)|
|
254
|
+
(daniel|dan|dn|dl|da)|
|
255
|
+
(hosea|hos|ho|hs)|
|
256
|
+
(joel|jl)|
|
257
|
+
(amos|amo|ams|am)|
|
258
|
+
(obadiah|obadia|obad|oba|obd|ob)|
|
259
|
+
(jonah|jon)|
|
260
|
+
(micah|mica|mic|mi)|
|
261
|
+
(nahum|nah|nahu|na)|
|
262
|
+
(habakk?uk|habk?)|
|
263
|
+
(zephaniah?|ze?ph?)|
|
264
|
+
(haggai|ha?gg?)|
|
265
|
+
(zechariah?|ze?ch?)|
|
266
|
+
(malachi|mal)|
|
267
|
+
\b(matthew|matt|mat|ma|mt)\b|
|
268
|
+
(mark|mrk|mk)|
|
269
|
+
(luke|luk|lk|lu)|
|
270
|
+
(john|joh|jon|jhn|jh|jo|jn)|
|
271
|
+
(acts|act|ac)|
|
272
|
+
(romans|roman|roms|rom|rms|ro|rm)|
|
273
|
+
(galatians|galatian|galat|gala|gal|ga)|
|
274
|
+
(ephesians?|eph?|ephe?s?)|
|
275
|
+
(philippians?|phi?l|php|phi|philipp?)|
|
276
|
+
(colossi?ans?|col?)|
|
277
|
+
(titus|tit|ti)|
|
278
|
+
(philemon|phl?mn?|philem?)|
|
279
|
+
(hebrews|hebrew|heb)|
|
280
|
+
(james|jam|jas|jm|js|ja)|
|
281
|
+
(jude)|
|
282
|
+
(revelations|revelation|revel|rev|rv|re)
|
283
|
+
)}ix.freeze
|
284
|
+
|
285
|
+
# The order books of the Bible are matched
|
286
|
+
BOOK_IDS = [ 64, 10, 12, 14, 63, 47, 53, 55, 61, 9, 11, 13, 62, 46, 52, 54, 60, 1, 2, 3, 4, 5, 6, 7, 8, 23, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 48, 49, 50, 51, 56, 57, 58, 59, 65, 66 ].freeze
|
287
|
+
|
288
|
+
BOOK_NAMES = [nil, "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalm", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation"].freeze
|
289
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Pericope
|
2
|
+
class Range
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(first, last)
|
6
|
+
@begin = first
|
7
|
+
@end = last
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :begin
|
11
|
+
attr_reader :end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
return true if equal? other
|
15
|
+
|
16
|
+
other.kind_of?(Pericope::Range) and
|
17
|
+
self.begin == other.begin and
|
18
|
+
self.end == other.end
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :eql?, :==
|
22
|
+
|
23
|
+
def hash
|
24
|
+
self.begin.hash ^ self.end.hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def each
|
28
|
+
return to_enum unless block_given?
|
29
|
+
|
30
|
+
if self.begin == self.end
|
31
|
+
yield self.begin
|
32
|
+
return self
|
33
|
+
end
|
34
|
+
|
35
|
+
current = self.begin
|
36
|
+
last_verse = self.end.whole
|
37
|
+
while current < last_verse
|
38
|
+
yield current
|
39
|
+
current = current.succ
|
40
|
+
end
|
41
|
+
|
42
|
+
if self.end.partial?
|
43
|
+
"a".upto(self.end.letter).each do |letter|
|
44
|
+
yield Verse.new(self.end.book, self.end.chapter, self.end.verse, letter)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
yield self.end
|
48
|
+
end
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
"#{self.begin.to_id}..#{self.end.to_id}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class Pericope
|
2
|
+
Verse = Struct.new(:book, :chapter, :verse, :letter) do
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
def initialize(book, chapter, verse, letter=nil)
|
6
|
+
super
|
7
|
+
|
8
|
+
raise ArgumentError, "#{book} is not a valid book" if book < 1 || book > 66
|
9
|
+
raise ArgumentError, "#{chapter} is not a valid chapter" if chapter < 1 || chapter > Pericope.get_max_chapter(book)
|
10
|
+
raise ArgumentError, "#{verse} is not a valid verse" if verse < 1 || verse > Pericope.get_max_verse(book, chapter)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parse(input)
|
14
|
+
return nil unless input
|
15
|
+
id = input.to_i
|
16
|
+
book = id / 1000000 # the book is everything left of the least significant 6 digits
|
17
|
+
chapter = (id % 1000000) / 1000 # the chapter is the 3rd through 6th most significant digits
|
18
|
+
verse = id % 1000 # the verse is the 3 least significant digits
|
19
|
+
letter = input[Pericope.letter_regexp] if input.is_a?(String)
|
20
|
+
new(book, chapter, verse, letter)
|
21
|
+
end
|
22
|
+
|
23
|
+
def <=>(other)
|
24
|
+
raise ArgumentError, "Comparison of Pericope::Verse with #{other.class} failed" unless other.is_a?(Pericope::Verse)
|
25
|
+
[ book, chapter, verse, letter || "a" ] <=> [ other.book, other.chapter, other.verse, other.letter || "a" ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
to_a == other.to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_i
|
33
|
+
book * 1000000 + chapter * 1000 + verse
|
34
|
+
end
|
35
|
+
alias :number :to_i
|
36
|
+
|
37
|
+
def to_id
|
38
|
+
"#{to_i}#{letter}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s(with_chapter: false)
|
42
|
+
with_chapter ? "#{chapter}:#{verse}#{letter}" : "#{verse}#{letter}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def partial?
|
46
|
+
!letter.nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
def whole?
|
50
|
+
letter.nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
def whole
|
54
|
+
return self unless partial?
|
55
|
+
self.class.new(book, chapter, verse)
|
56
|
+
end
|
57
|
+
|
58
|
+
def next
|
59
|
+
if partial? && (next_letter = letter.succ) <= Pericope.max_letter
|
60
|
+
return self.class.new(book, chapter, verse, next_letter)
|
61
|
+
end
|
62
|
+
|
63
|
+
next_verse = verse + 1
|
64
|
+
if next_verse > Pericope.get_max_verse(book, chapter)
|
65
|
+
next_chapter = chapter + 1
|
66
|
+
return nil if next_chapter > Pericope.get_max_chapter(book)
|
67
|
+
self.class.new(book, next_chapter, 1)
|
68
|
+
else
|
69
|
+
self.class.new(book, chapter, next_verse)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
alias :succ :next
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|