Class: Scripref::Formatter
- Inherits:
-
Object
- Object
- Scripref::Formatter
- Defined in:
- lib/scripref/formatter.rb
Instance Method Summary collapse
-
#fullref(*reference) ⇒ Object
Formats a reference (array of passages) with full book names (i.e. Hebrews 3:8).
-
#initialize(*mods) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(*mods) ⇒ Formatter
Returns a new instance of Formatter.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/scripref/formatter.rb', line 8 def initialize *mods @mods = mods mods.each do |m| m.class_eval do extend ConstReader const_accessor constants end extend m end end |
Instance Method Details
#fullref(*reference) ⇒ Object
Formats a reference (array of passages) with full book names (i.e. Hebrews 3:8)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scripref/formatter.rb', line 21 def fullref *reference last_b = last_c = last_v = nil pass_texts = reference.flatten.map do |pass| changed = false s = '' if changed || last_b != pass.b1 s << book_names[pass.b1 - 1] last_b = pass.b1 changed = true end if changed || last_c != pass.c1 s << ' ' if ! Scripref.book_has_only_one_chapter?(pass.b1) s << pass.c1.to_s end last_c = pass.c1 changed = true end if changed || last_v != pass.v1 if ! Scripref.book_has_only_one_chapter?(pass.b1) s << cv_separator end s << pass.v1.to_s last_v = pass.v1 changed = true end # second part changed = false a2 = [] if changed || last_b != pass.b2 a2 << book_names[pass.b2 - 1] last_b = pass.b2 changed = true end if changed || last_c != pass.c2 a2 << ' ' if pass.b1 != pass.b2 if ! Scripref.book_has_only_one_chapter?(pass.b2) a2 << pass.c2.to_s a2 << cv_separator end last_c = pass.c2 changed = true end if changed || last_v != pass.v2 a2 << pass.v2.to_s last_v = pass.v2 changed = true end if ! a2.empty? s << hyphen_separator s << a2.join('') end s end pass_texts.join(pass_separator) end |