Class: TimeBoots::Lace

Inherits:
Object
  • Object
show all
Defined in:
lib/time_boots/lace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step, from, to, options = {}) ⇒ Lace

Returns a new instance of Lace.



4
5
6
7
8
9
10
# File 'lib/time_boots/lace.rb', line 4

def initialize(step, from, to, options = {})
  @boot = Boot.get(step)
  @from, @to = from, to
  @options = options.dup

  expand! if options[:expand]
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



12
13
14
# File 'lib/time_boots/lace.rb', line 12

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



12
13
14
# File 'lib/time_boots/lace.rb', line 12

def to
  @to
end

Instance Method Details

#expandObject



21
22
23
# File 'lib/time_boots/lace.rb', line 21

def expand
  dup.tap(&:expand!)
end

#expand!Object



14
15
16
17
18
19
# File 'lib/time_boots/lace.rb', line 14

def expand!
  @from = boot.floor(from)
  @to = boot.ceil(to)

  self
end

#inspectObject



47
48
49
# File 'lib/time_boots/lace.rb', line 47

def inspect
  "#<#{self.class}(#{from} - #{to})>"
end

#pull(beginnings = false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/time_boots/lace.rb', line 25

def pull(beginnings = false)
  seq = []

  iter = from
  while iter < to
    seq << iter

    iter = cond_floor(boot.advance(iter), beginnings)
  end

  seq
end

#pull_pairs(beginnings = false) ⇒ Object



38
39
40
41
# File 'lib/time_boots/lace.rb', line 38

def pull_pairs(beginnings = false)
  seq = pull(beginnings)
  seq.zip(seq[1..-1] + [to])
end

#pull_ranges(beginnings = false) ⇒ Object



43
44
45
# File 'lib/time_boots/lace.rb', line 43

def pull_ranges(beginnings = false)
  pull_pairs(beginnings).map { |b, e| (b...e) }
end