Class: Flapjack::Diner::IndexRange
- Inherits:
-
Object
- Object
- Flapjack::Diner::IndexRange
- Defined in:
- lib/flapjack-diner/index_range.rb
Instance Attribute Summary collapse
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
-
#initialize(start, finish, opts = {}) ⇒ IndexRange
constructor
A new instance of IndexRange.
-
#to_s ⇒ Object
NB.
Constructor Details
#initialize(start, finish, opts = {}) ⇒ IndexRange
Returns a new instance of IndexRange.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flapjack-diner/index_range.rb', line 9 def initialize(start, finish, opts = {}) value_types = [Float, Date, Time, DateTime] [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 if start.nil? && finish.nil? raise "Range must be bounded on at least one side" end @start = start @finish = finish end |
Instance Attribute Details
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
7 8 9 |
# File 'lib/flapjack-diner/index_range.rb', line 7 def finish @finish end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
7 8 9 |
# File 'lib/flapjack-diner/index_range.rb', line 7 def start @start end |
Instance Method Details
#to_s ⇒ Object
NB
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flapjack-diner/index_range.rb', line 25 def to_s start_s = case @start when Date, Time, DateTime @start.iso8601 else @start.to_s end finish_s = case @finish when Date, Time, DateTime @finish.iso8601 else @finish.to_s end "#{start_s}..#{finish_s}" end |