Class: Zermelo::Filters::IndexRange

Inherits:
Object
  • Object
show all
Defined in:
lib/zermelo/filters/index_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, finish, opts = {}) ⇒ IndexRange

Returns a new instance of IndexRange.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/zermelo/filters/index_range.rb', line 7

def initialize(start, finish, opts = {})
  value_types = opts[:by_score] ? [Float, Date, Time, DateTime] : [Integer]
  [start, finish].each do |v|
    raise "Values must be #{value_types.join('/')}" unless v.nil? || value_types.any? {|vt| v.is_a?(vt)}
  end
  if !start.nil? && !finish.nil? && (start > finish)
    raise "Start of range must be <= finish"
  end
  @start    = start
  @finish   = finish
  @by_score = opts[:by_score]
end

Instance Attribute Details

#by_scoreObject (readonly)

Returns the value of attribute by_score.



5
6
7
# File 'lib/zermelo/filters/index_range.rb', line 5

def by_score
  @by_score
end

#finishObject (readonly)

Returns the value of attribute finish.



5
6
7
# File 'lib/zermelo/filters/index_range.rb', line 5

def finish
  @finish
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/zermelo/filters/index_range.rb', line 5

def start
  @start
end