Class: Suprdate::Builder

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

Overview

Creates date objects of classes such as Year, Month and Day.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



8
9
10
11
# File 'lib/suprdate/builder.rb', line 8

def initialize
  @day_factory = Day
  @month_factory = Month
end

Instance Attribute Details

#day_factoryObject

Returns the value of attribute day_factory.



6
7
8
# File 'lib/suprdate/builder.rb', line 6

def day_factory
  @day_factory
end

#month_factoryObject

Returns the value of attribute month_factory.



6
7
8
# File 'lib/suprdate/builder.rb', line 6

def month_factory
  @month_factory
end

Class Method Details

.builder_methodsObject

Returns the names of the methods that create objects. Each name as a singleton #to_export method that can be used to ascertain the name of the exported version of the method that appears on Suprdate.



55
56
57
58
59
# File 'lib/suprdate/builder.rb', line 55

def self.builder_methods
  local_methods.reject { |name| name =~ /_/ }.each do |name|
    def name.to_export() capitalize end
  end
end

.local_methodsObject

:nodoc:



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

def self.local_methods # :nodoc:
  (instance_methods - superclass.instance_methods - Kernel.methods)
end

Instance Method Details

#date(*parts) ⇒ Object

Creates either an instead of either Suprdate::Year, Suprdate::Month or Suprdate::Day depending on the number of arguments (parts) used.



41
42
43
44
45
46
# File 'lib/suprdate/builder.rb', line 41

def date(*parts)
  unless DATE_NUM_PARTS_RANGE.include?(parts.nitems)
    raise DateConstructionError.invalid_part_count(parts)
  end
  send(UNIT_NUM_PARTS[parts.nitems], *parts)
end

#day(year_value, month_value, day_value) ⇒ Object

Creates an instance of Suprdate::Day.



29
30
31
# File 'lib/suprdate/builder.rb', line 29

def day(year_value, month_value, day_value)
  @day_factory.new(month(year_value, month_value), day_value)
end

#month(year_value, month_value) ⇒ Object

Creates an instance of Suprdate::Month.



22
23
24
25
26
# File 'lib/suprdate/builder.rb', line 22

def month(year_value, month_value)
  m = @month_factory.new(year(year_value), month_value)
  m.day_factory = @day_factory
  m
end

#todayObject

An instance of Suprdate::Day representing the current day.



34
35
36
37
# File 'lib/suprdate/builder.rb', line 34

def today
  time = Time.now
  day(time.year, time.month, time.day)
end

#year(value) ⇒ Object

Creates an instance of Suprdate::Year.



14
15
16
17
18
19
# File 'lib/suprdate/builder.rb', line 14

def year(value)
  y = Year.new(value)
  y.day_factory = @day_factory
  y.month_factory = @month_factory
  y
end