Class: Suprdate::Builder
- Inherits:
-
Object
- Object
- Suprdate::Builder
- Defined in:
- lib/suprdate/builder.rb
Overview
Creates date objects of classes such as Year, Month and Day.
Instance Attribute Summary collapse
-
#day_factory ⇒ Object
Returns the value of attribute day_factory.
-
#month_factory ⇒ Object
Returns the value of attribute month_factory.
Class Method Summary collapse
-
.builder_methods ⇒ Object
Returns the names of the methods that create objects.
-
.local_methods ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#date(*parts) ⇒ Object
Creates either an instead of either Suprdate::Year, Suprdate::Month or Suprdate::Day depending on the number of arguments (parts) used.
-
#day(year_value, month_value, day_value) ⇒ Object
Creates an instance of Suprdate::Day.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
-
#month(year_value, month_value) ⇒ Object
Creates an instance of Suprdate::Month.
-
#today ⇒ Object
An instance of Suprdate::Day representing the current day.
-
#year(value) ⇒ Object
Creates an instance of Suprdate::Year.
Constructor Details
Instance Attribute Details
#day_factory ⇒ Object
Returns the value of attribute day_factory.
6 7 8 |
# File 'lib/suprdate/builder.rb', line 6 def day_factory @day_factory end |
#month_factory ⇒ Object
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_methods ⇒ Object
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_methods ⇒ Object
: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 |
#today ⇒ Object
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 |