Class: Scripref::Passage

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/scripref/passage.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.book_id2numObject (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

#a1Object

Returns the value of attribute a1

Returns:

  • (Object)

    the current value of a1



6
7
8
# File 'lib/scripref/passage.rb', line 6

def a1
  @a1
end

#a2Object

Returns the value of attribute a2

Returns:

  • (Object)

    the current value of a2



6
7
8
# File 'lib/scripref/passage.rb', line 6

def a2
  @a2
end

#b1Object

Returns the value of attribute b1

Returns:

  • (Object)

    the current value of b1



6
7
8
# File 'lib/scripref/passage.rb', line 6

def b1
  @b1
end

#b2Object

Returns the value of attribute b2

Returns:

  • (Object)

    the current value of b2



6
7
8
# File 'lib/scripref/passage.rb', line 6

def b2
  @b2
end

#c1Object

Returns the value of attribute c1

Returns:

  • (Object)

    the current value of c1



6
7
8
# File 'lib/scripref/passage.rb', line 6

def c1
  @c1
end

#c2Object

Returns the value of attribute c2

Returns:

  • (Object)

    the current value of c2



6
7
8
# File 'lib/scripref/passage.rb', line 6

def c2
  @c2
end

#textObject Also known as: to_s

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



6
7
8
# File 'lib/scripref/passage.rb', line 6

def text
  @text
end

#v1Object

Returns the value of attribute v1

Returns:

  • (Object)

    the current value of v1



6
7
8
# File 'lib/scripref/passage.rb', line 6

def v1
  @v1
end

#v2Object

Returns the value of attribute v2

Returns:

  • (Object)

    the current value of 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

#endObject

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.

Returns:

  • (Boolean)


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

#startObject

Returns an array of b1, c1, v1



29
30
31
# File 'lib/scripref/passage.rb', line 29

def start
  [b1, c1, v1]
end

#to_aObject



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