Class: Blackcal::Builder

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

Overview

Builder provides a DSL for schedule options

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder



18
19
20
# File 'lib/blackcal/builder.rb', line 18

def initialize
  @data = {}
end

Class Method Details

.dsl(&block) ⇒ Builder

Enables a DSL for building schedule options

Examples:

Blackcal.dsl do
  months [:january]
  days 15..25
end

Returns:



13
14
15
# File 'lib/blackcal/builder.rb', line 13

def self.dsl(&block)
  new.tap { |b| b.instance_eval(&block) }
end

Instance Method Details

#days(*days) ⇒ Object

Parameters:

  • days (Array<Integer>, Integer, nil)


58
59
60
# File 'lib/blackcal/builder.rb', line 58

def days(*days)
  @data[:days] = flat_array(days)
end

#finish_hour_of_day(finish_hour_of_day) ⇒ Object

Parameters:

  • finish_hour_of_day (TimeOfDay, Time, Integer, nil)


38
39
40
# File 'lib/blackcal/builder.rb', line 38

def finish_hour_of_day(finish_hour_of_day)
  @data[:finish_hour_of_day] = finish_hour_of_day
end

#finish_time(finish_time) ⇒ Object

Parameters:

  • finish_time (Time, Date, String, nil)


28
29
30
# File 'lib/blackcal/builder.rb', line 28

def finish_time(finish_time)
  @data[:finish_time] = finish_time
end

#months(*months) ⇒ Object

Parameters:

  • months (Array<String>, Array<Symbol>, String, Symbol, nil)


43
44
45
# File 'lib/blackcal/builder.rb', line 43

def months(*months)
  @data[:months] = flat_array(months)
end

#start_time(start_time) ⇒ Object

Parameters:

  • start_time (Time, Date, String, nil)


23
24
25
# File 'lib/blackcal/builder.rb', line 23

def start_time(start_time)
  @data[:start_time] = start_time
end

#start_time_of_day(start_time_of_day) ⇒ Object

Parameters:

  • start_time_of_day (TimeOfDay, Time, Integer, nil)


33
34
35
# File 'lib/blackcal/builder.rb', line 33

def start_time_of_day(start_time_of_day)
  @data[:start_time_of_day] = start_time_of_day
end

#to_hHash

The builder represented as a hash

Returns:

  • (Hash)


64
65
66
# File 'lib/blackcal/builder.rb', line 64

def to_h
  @data
end

#weekdays(*weekdays) ⇒ Object

Parameters:

  • weekdays (Array<String>, Array<Symbol>, String, Symbol, nil)


48
49
50
# File 'lib/blackcal/builder.rb', line 48

def weekdays(*weekdays)
  @data[:weekdays] = flat_array(weekdays)
end

#weeks_of_month(*weeks_of_month) ⇒ Object

Parameters:

  • weeks_of_month (Array<Integer>, nil)


53
54
55
# File 'lib/blackcal/builder.rb', line 53

def weeks_of_month(*weeks_of_month)
  @data[:weeks_of_month] = flat_array(weeks_of_month)
end