Class: Toji::Progress::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/toji/progress/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(progress_cls, state_cls) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
9
10
11
# File 'lib/toji/progress/builder.rb', line 5

def initialize(progress_cls, state_cls)
  @progress_cls = progress_cls
  @state_cls = state_cls
  @states = []
  @date_line = 0
  @prefix_day_labels = nil
end

Instance Method Details

#<<(state) ⇒ Object Also known as: add



13
14
15
16
17
18
19
20
21
22
# File 'lib/toji/progress/builder.rb', line 13

def <<(state)
  @states += [state].flatten.map {|state|
    if State===state
      state
    else
      @state_cls.create(state)
    end
  }
  self
end

#buildObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/toji/progress/builder.rb', line 35

def build
  progress = @progress_cls.new

  states = @states.map{|s|
    s.progress = progress
    s
  }.sort_by(&:time)

  progress.states = states
  progress. = @date_line
  if progress.respond_to?(:prefix_day_labels=)
    progress.prefix_day_labels = @prefix_day_labels
  end

  progress
end

#date_line(val, unit = SECOND) ⇒ Object



25
26
27
28
# File 'lib/toji/progress/builder.rb', line 25

def (val, unit=SECOND)
  @date_line = (val * unit).to_i
  self
end

#prefix_day_labels(val) ⇒ Object



30
31
32
33
# File 'lib/toji/progress/builder.rb', line 30

def prefix_day_labels(val)
  @prefix_day_labels = val
  self
end