Class: TurbaChronos::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/turba_chronos/timeline.rb

Defined Under Namespace

Classes: TempTimeframe

Instance Method Summary collapse

Constructor Details

#initialize(periods, from, to) ⇒ Timeline

Returns a new instance of Timeline.



3
4
5
6
7
# File 'lib/turba_chronos/timeline.rb', line 3

def initialize(periods, from, to)
  @periods = Periods.new(periods).complete
  @from = from
  @to = to
end

Instance Method Details

#business_timerangesObject



9
10
11
12
13
# File 'lib/turba_chronos/timeline.rb', line 9

def business_timeranges
  timeranges_for_days[:business_timeranges].map! {|x|
    [x.min.to_s.rjust(4, '0').insert(2, ':'), x.max.to_s.rjust(4, '0').insert(2, ':')]
  }
end

#current_dayObject



27
28
29
# File 'lib/turba_chronos/timeline.rb', line 27

def current_day
  @current_day ||= days.first
end

#current_timeframeObject



59
60
61
# File 'lib/turba_chronos/timeline.rb', line 59

def current_timeframe
  current_day.current_timeframe
end

#daysObject



23
24
25
# File 'lib/turba_chronos/timeline.rb', line 23

def days
  @days ||= get_days(@from, @to)
end

#levelsObject



15
16
17
# File 'lib/turba_chronos/timeline.rb', line 15

def levels
  @levels ||= days.map(&:timeframes).flatten.map(&:level).uniq
end

#nextObject



35
36
37
# File 'lib/turba_chronos/timeline.rb', line 35

def next
  get_list(days)[0..2]
end

#opened?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/turba_chronos/timeline.rb', line 31

def opened?
  current_day.opened?
end

#reopenObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/turba_chronos/timeline.rb', line 39

def reopen
  get_list(days).each do |data|
    return data if data.timeframe.level != 6
  end

  iteration = 14
  count = 0
  loop do
    if count == 0
      next_days = get_days(@to+1.day, @to+iteration.days)
    else
      next_days = get_days((@to+(count * iteration).days), (@to+((count+1) * iteration).days))
    end
    get_list(next_days).each do |data|
      return data if data.timeframe.level != 6
    end
    count += 1
  end
end

#timeranges_for_daysObject



19
20
21
# File 'lib/turba_chronos/timeline.rb', line 19

def timeranges_for_days
  @timeranges_for_days ||= get_timeranges_for_days(@from, @to)
end