Class: EDTF::Interval

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/edtf/interval.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from = :open, to = :open) ⇒ Interval

Returns a new instance of Interval.



13
14
15
# File 'lib/edtf/interval.rb', line 13

def initialize(from = :open, to = :open)
  @from, @to = from, to
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



11
12
13
# File 'lib/edtf/interval.rb', line 11

def from
  @from
end

#toObject

Returns the value of attribute to.



11
12
13
# File 'lib/edtf/interval.rb', line 11

def to
  @to
end

Instance Method Details

#boundsObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/edtf/interval.rb', line 64

def bounds
  case
  when open_end?, to.day_precision? 
    to
  when to.month_precision?
    to.end_of_month
  else
    to.end_of_year
  end
end

#edtfObject Also known as: to_s



75
76
77
78
79
80
# File 'lib/edtf/interval.rb', line 75

def edtf
	[
		@from.send(@from.respond_to?(:edtf) ? :edtf : :to_s),
		@to.send(@to.respond_to?(:edtf) ? :edtf : :to_s)
	].join('/')
end

#to_rangeObject

TODO how to handle +/- Infinity for Dates?



53
54
55
56
57
58
59
60
61
62
# File 'lib/edtf/interval.rb', line 53

def to_range
  case
  when open?
    nil
  when unknown_end?
    nil
  else
    Range.new(unknown_start? ? Date.new : @from, bounds)
  end
end

#unknown_start!Object



47
48
49
# File 'lib/edtf/interval.rb', line 47

def unknown_start!
  @from = :unknown
end

#unknown_start?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/edtf/interval.rb', line 43

def unknown_start?
  @from == :unknown
end