Class: Geoptima::DateRange

Inherits:
Object
  • Object
show all
Defined in:
lib/geoptima/daterange.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max = nil) ⇒ DateRange

Returns a new instance of DateRange.



22
23
24
25
26
# File 'lib/geoptima/daterange.rb', line 22

def initialize(min,max=nil)
  @min = min
  @max = max || (min + 1.0)
  @range = Range.new(@min,@max)
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



21
22
23
# File 'lib/geoptima/daterange.rb', line 21

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



21
22
23
# File 'lib/geoptima/daterange.rb', line 21

def min
  @min
end

#rangeObject (readonly)

Returns the value of attribute range.



21
22
23
# File 'lib/geoptima/daterange.rb', line 21

def range
  @range
end

Class Method Details

.from(spec) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/geoptima/daterange.rb', line 41

def self.from(spec)
  if spec =~ /\.\./
    puts "New time range spec: #{spec}" if($debug)
    DateRanges.new(spec)
  elsif spec.split(/\,/).length > 2
    puts "New days array: #{spec}" if($debug)
    DaysRange.new(spec)
  else
    puts "Classic time range: #{spec}" if($debug)
    DateRange.new(*spec.split(/\,/).map{|t| DateTime.parse(t)})
  end
end

.testObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/geoptima/daterange.rb', line 53

def self.test
  [
    '2012-03-15,2012-03-16',
    '2012-03-15..2012-03-16',
    '2012-03-15..2012-03-20',
    '2012-03-15..2012-03-16,2012-03-20..2012.03.21',
    '2012-03-15..2012-03-16,2012-03-20',
    '2012-03-15,2012-03-16,2012-03-20'
  ].each do |test|
    puts "Testing: #{test}"
    puts "\t#{Geoptima::DateRange.from(test)}"
  end
end

Instance Method Details

#include?(time) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/geoptima/daterange.rb', line 29

def include?(time)
  @range.include?(time)
end

#to_sObject



38
39
40
# File 'lib/geoptima/daterange.rb', line 38

def to_s
  @range.to_s
end