pericope 0.6.5 → 0.6.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab67c11e856b86c538704505aab0d04ac0fbae42
4
- data.tar.gz: 2a76d75eec804384c8e80dca7b6e887d0b5d3882
3
+ metadata.gz: e9520cfcbbe46071bc2f891a3eb1cd2c4790b88b
4
+ data.tar.gz: 06d8cc8008621dd923b08054a63cfb627f532f57
5
5
  SHA512:
6
- metadata.gz: 31d08e0db1237a628c3bfc030dd369b6da47ea7ffcc754902e93ec0f220ec70ef3c2c1bb8c0691bc109b003944c1131ae68060700bc7aa0d3813fc5b29eee504
7
- data.tar.gz: 887c38d4c421b9b56cba1072d16b28d49d342ffb17b37fa2e0e3d2066ab9ab4d668138c646e6a51f012a60b2f0c3cf772c57f6e5bd2194384e15bced497c4ee4
6
+ metadata.gz: 1b8e7a0866232493e1bd8b36d80ff5baefa278df4f76129e6f130e56cc2a73b4190aa9ef26a2555399733c583f76315608d140ff6787fb91473a0b56af4757c2
7
+ data.tar.gz: 643ca5b7bdcd8fcaef115c2afd7c13a91c835c0d6b520422c90cdf63211570a124039bd223a832b5f8c0c972caef7ed70d10cc4211df37df817357488c7d0012
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pericope"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.expand_path("../../lib", __FILE__)
4
- require 'pericope/cli'
4
+ require "pericope/cli"
5
5
 
6
6
  command = ARGV.shift
7
7
  arguments = ARGV
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'pericope/version'
3
+ require "pericope/version"
4
4
 
5
5
  class Pericope
6
6
  attr_reader :book,
@@ -54,7 +54,7 @@ class Pericope
54
54
 
55
55
 
56
56
  def self.book_has_chapters?(book)
57
- book_chapter_counts[book - 1] > 1
57
+ book_chapter_counts[book] > 1
58
58
  end
59
59
 
60
60
  def book_has_chapters?
@@ -172,8 +172,8 @@ class Pericope
172
172
 
173
173
 
174
174
 
175
- def to_s
176
- "#{book_name} #{self.well_formatted_reference}"
175
+ def to_s(options={})
176
+ "#{book_name} #{well_formatted_reference(options)}"
177
177
  end
178
178
 
179
179
 
@@ -209,19 +209,34 @@ class Pericope
209
209
 
210
210
 
211
211
 
212
- def well_formatted_reference
212
+ def well_formatted_reference(options={})
213
213
  recent_chapter = nil # e.g. in 12:1-8, remember that 12 is the chapter when we parse the 8
214
214
  recent_chapter = 1 unless book_has_chapters?
215
- ranges.map do |range|
215
+
216
+ verse_range_separator = options.fetch(:verse_range_separator, "–") # en-dash
217
+ chapter_range_separator = options.fetch(:chapter_range_separator, "—") # em-dash
218
+ verse_list_separator = options.fetch(:verse_list_separator, ", ")
219
+ chapter_list_separator = options.fetch(:chapter_list_separator, "; ")
220
+ always_print_verse_range = options.fetch(:always_print_verse_range, false)
221
+
222
+ s = ""
223
+ ranges.each_with_index do |range, i|
216
224
  min_chapter = Pericope.get_chapter(range.begin)
217
225
  min_verse = Pericope.get_verse(range.begin)
218
226
  max_chapter = Pericope.get_chapter(range.end)
219
227
  max_verse = Pericope.get_verse(range.end)
220
- s = ""
221
228
 
222
- if min_verse == 1 and max_verse >= Pericope.get_max_verse(book, max_chapter)
229
+ if i > 0
230
+ if recent_chapter == min_chapter
231
+ s << verse_list_separator
232
+ else
233
+ s << chapter_list_separator
234
+ end
235
+ end
236
+
237
+ if min_verse == 1 && max_verse >= Pericope.get_max_verse(book, max_chapter) && !always_print_verse_range
223
238
  s << min_chapter.to_s
224
- s << "-#{max_chapter}" if max_chapter > min_chapter
239
+ s << "#{chapter_range_separator}#{max_chapter}" if max_chapter > min_chapter
225
240
  else
226
241
  if recent_chapter == min_chapter
227
242
  s << min_verse.to_s
@@ -232,18 +247,17 @@ class Pericope
232
247
 
233
248
  if range.count > 1
234
249
 
235
- s << "-"
236
250
  if min_chapter == max_chapter
237
- s << max_verse.to_s
251
+ s << "#{verse_range_separator}#{max_verse}"
238
252
  else
239
253
  recent_chapter = max_chapter
240
- s << "#{max_chapter}:#{max_verse}"
254
+ s << "#{chapter_range_separator}#{max_chapter}:#{max_verse}"
241
255
  end
242
256
  end
243
257
  end
258
+ end
244
259
 
245
- s
246
- end.join(", ")
260
+ s
247
261
  end
248
262
 
249
263
 
@@ -269,7 +283,7 @@ class Pericope
269
283
  end
270
284
 
271
285
  def self.get_max_chapter(book)
272
- book_chapter_counts[book - 1]
286
+ book_chapter_counts[book]
273
287
  end
274
288
 
275
289
 
@@ -280,8 +294,8 @@ private
280
294
 
281
295
  def set_book(value)
282
296
  @book = value || raise(ArgumentError, "must specify book")
283
- @book_name = Pericope.book_names[@book - 1]
284
- @book_chapter_count = Pericope.book_chapter_counts[@book - 1]
297
+ @book_name = Pericope.book_names[@book]
298
+ @book_chapter_count = Pericope.book_chapter_counts[@book]
285
299
  end
286
300
 
287
301
 
@@ -482,7 +496,7 @@ private
482
496
  current_book_id = nil
483
497
  chapters = 0
484
498
  @chapter_verse_counts = {}
485
- @book_chapter_counts = []
499
+ @book_chapter_counts = [{}]
486
500
 
487
501
  path = File.expand_path(File.dirname(__FILE__) + "/../data/chapter_verse_count.txt")
488
502
  File.open(path) do |file|
@@ -522,7 +536,7 @@ private
522
536
  # as the aforementioned book.
523
537
  segments = text.chomp.split("\t")
524
538
  book_id = segments.shift.to_i
525
- @book_names[book_id - 1] = segments.shift
539
+ @book_names[book_id] = segments.shift
526
540
  @book_name_regexes[book_id] = /\b(?:#{segments.join("|")})\b/
527
541
  end
528
542
  end
@@ -1,5 +1,5 @@
1
- require 'pericope'
2
- require 'cli/base'
1
+ require "pericope"
2
+ require "cli/base"
3
3
 
4
4
  class Pericope
5
5
  class CLI
@@ -1,3 +1,3 @@
1
1
  class Pericope
2
- VERSION = "0.6.5" unless defined?(::Pericope::Version)
2
+ VERSION = "0.6.6" unless defined?(::Pericope::Version)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pericope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -106,6 +106,7 @@ extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
108
  - README.mdown
109
+ - bin/console
109
110
  - bin/pericope
110
111
  - data/book_abbreviations.txt
111
112
  - data/chapter_verse_count.txt