Class: Scripref::Passage
- Inherits:
-
Struct
- Object
- Struct
- Scripref::Passage
- Includes:
- Comparable
- Defined in:
- lib/scripref/passage.rb
Class Attribute Summary collapse
-
.book_id2num ⇒ Object
readonly
Returns the value of attribute book_id2num.
Instance Attribute Summary collapse
-
#a1 ⇒ Object
Returns the value of attribute a1.
-
#a2 ⇒ Object
Returns the value of attribute a2.
-
#b1 ⇒ Object
Returns the value of attribute b1.
-
#b2 ⇒ Object
Returns the value of attribute b2.
-
#c1 ⇒ Object
Returns the value of attribute c1.
-
#c2 ⇒ Object
Returns the value of attribute c2.
-
#text ⇒ Object
(also: #to_s)
Returns the value of attribute text.
-
#v1 ⇒ Object
Returns the value of attribute v1.
-
#v2 ⇒ Object
Returns the value of attribute v2.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#end ⇒ Object
Returns an array of b2, c2, v2.
-
#overlap?(passage) ⇒ Boolean
Returns true if the instance and the given passage overlap.
-
#start ⇒ Object
Returns an array of b1, c1, v1.
- #to_a ⇒ Object
- #to_numeric_array(max: 999, ff: 3) ⇒ Object
Class Attribute Details
.book_id2num ⇒ Object (readonly)
Returns the value of attribute book_id2num.
69 70 71 |
# File 'lib/scripref/passage.rb', line 69 def book_id2num @book_id2num end |
Instance Attribute Details
#a1 ⇒ Object
Returns the value of attribute a1
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def a1 @a1 end |
#a2 ⇒ Object
Returns the value of attribute a2
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def a2 @a2 end |
#b1 ⇒ Object
Returns the value of attribute b1
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def b1 @b1 end |
#b2 ⇒ Object
Returns the value of attribute b2
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def b2 @b2 end |
#c1 ⇒ Object
Returns the value of attribute c1
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def c1 @c1 end |
#c2 ⇒ Object
Returns the value of attribute c2
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def c2 @c2 end |
#text ⇒ Object Also known as: to_s
Returns the value of attribute text
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def text @text end |
#v1 ⇒ Object
Returns the value of attribute v1
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def v1 @v1 end |
#v2 ⇒ Object
Returns the value of attribute v2
6 7 8 |
# File 'lib/scripref/passage.rb', line 6 def v2 @v2 end |
Instance Method Details
#<=>(other) ⇒ Object
14 15 16 17 |
# File 'lib/scripref/passage.rb', line 14 def <=> other return unless other.kind_of? Passage self.to_numeric_array <=> other.to_numeric_array end |
#end ⇒ Object
Returns an array of b2, c2, v2
34 35 36 |
# File 'lib/scripref/passage.rb', line 34 def end [b2, c2, v2] end |
#overlap?(passage) ⇒ Boolean
Returns true if the instance and the given passage overlap. That means both has at least one verse in common.
21 22 23 24 25 26 |
# File 'lib/scripref/passage.rb', line 21 def overlap? passage fail ArgumentError, 'value must be a passage' unless passage.kind_of? Passage a = self.to_numeric_array b = passage.to_numeric_array [a[0..2] <=> b[3..5], b[0..2] <=> a[3..5]].max < 1 end |
#start ⇒ Object
Returns an array of b1, c1, v1
29 30 31 |
# File 'lib/scripref/passage.rb', line 29 def start [b1, c1, v1] end |
#to_a ⇒ Object
10 11 12 |
# File 'lib/scripref/passage.rb', line 10 def to_a [b1, c1, v1, b2, c2, v2] end |
#to_numeric_array(max: 999, ff: 3) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/scripref/passage.rb', line 38 def to_numeric_array max: 999, ff: 3 _b1 = Passage.book_id2num[b1] _c1 = c1 || 1 _v1 = v1 || 1 _b2 = Passage.book_id2num[b2] _c2 = c2 || max _v2 = v2 || max if _v2 == :f _v2 = _v1 + 1 end if _v2 == :ff _v2 = _v1 + ff end [_b1, _c1, _v1, _b2, _c2, _v2] end |