Class: Financial::Parcels
Instance Attribute Summary collapse
-
#beginning_month ⇒ Object
readonly
Returns the value of attribute beginning_month.
-
#day_of_the_parcels ⇒ Object
readonly
Returns the value of attribute day_of_the_parcels.
-
#month_number ⇒ Object
readonly
Returns the value of attribute month_number.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#value_of_the_parcels ⇒ Object
readonly
Returns the value of attribute value_of_the_parcels.
Attributes inherited from Cost
Instance Method Summary collapse
- #beginning(month) ⇒ Object
-
#choose_month_for(parcel_number) ⇒ Object
TODO: Change this procedural code :.
-
#choose_year_for(options) ⇒ Object
TODO: Change this procedural code :.
- #day_of_the_parcel_is_in_this_month? ⇒ Boolean
- #every_day(day) ⇒ Object
-
#initialize(number_of_parcels) ⇒ Parcels
constructor
A new instance of Parcels.
- #of(value) ⇒ Object
- #to_cost ⇒ Object
- #value ⇒ Object
Methods inherited from Cost
#+, #==, #format_value, #in_date, #is_a_received_deposit?
Constructor Details
#initialize(number_of_parcels) ⇒ Parcels
Returns a new instance of Parcels.
6 7 8 9 10 11 12 |
# File 'lib/financial/parcels.rb', line 6 def initialize(number_of_parcels) @name = Financial.locale.name_of_the_parcel @number = number_of_parcels @day_of_the_parcels = 1 @value_of_the_parcels = 0 @beginning_month = Date.today.month end |
Instance Attribute Details
#beginning_month ⇒ Object (readonly)
Returns the value of attribute beginning_month.
4 5 6 |
# File 'lib/financial/parcels.rb', line 4 def beginning_month @beginning_month end |
#day_of_the_parcels ⇒ Object (readonly)
Returns the value of attribute day_of_the_parcels.
4 5 6 |
# File 'lib/financial/parcels.rb', line 4 def day_of_the_parcels @day_of_the_parcels end |
#month_number ⇒ Object (readonly)
Returns the value of attribute month_number.
4 5 6 |
# File 'lib/financial/parcels.rb', line 4 def month_number @month_number end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/financial/parcels.rb', line 3 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/financial/parcels.rb', line 3 def number @number end |
#value_of_the_parcels ⇒ Object (readonly)
Returns the value of attribute value_of_the_parcels.
4 5 6 |
# File 'lib/financial/parcels.rb', line 4 def value_of_the_parcels @value_of_the_parcels end |
Instance Method Details
#beginning(month) ⇒ Object
24 25 26 27 |
# File 'lib/financial/parcels.rb', line 24 def beginning(month) @beginning_month = Financial.locale.month_for(month) self end |
#choose_month_for(parcel_number) ⇒ Object
TODO: Change this procedural code :\
46 47 48 49 50 51 52 53 54 |
# File 'lib/financial/parcels.rb', line 46 def choose_month_for(parcel_number) months = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] index = @beginning_month - 1 + parcel_number if index >= 12 months[index - 12] else months[index] end end |
#choose_year_for(options) ⇒ Object
TODO: Change this procedural code :\
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/financial/parcels.rb', line 58 def choose_year_for() parcel_number = [:parcel_number] @current_year = current_date.year @month_number = @beginning_month + parcel_number if @month_number >= 12 find_year_for_parcel else @current_year end end |
#day_of_the_parcel_is_in_this_month? ⇒ Boolean
40 41 42 |
# File 'lib/financial/parcels.rb', line 40 def day_of_the_parcel_is_in_this_month? @day_of_the_parcels >= @today.day end |
#every_day(day) ⇒ Object
19 20 21 22 |
# File 'lib/financial/parcels.rb', line 19 def every_day(day) @day_of_the_parcels = day self end |
#of(value) ⇒ Object
14 15 16 17 |
# File 'lib/financial/parcels.rb', line 14 def of(value) @value_of_the_parcels = value self end |
#to_cost ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/financial/parcels.rb', line 29 def to_cost @today = Date.today number.times.collect do |parcel_number| day = @day_of_the_parcels month = choose_month_for(parcel_number) year = choose_year_for(:parcel_number => parcel_number) date = Financial.locale.right_date_format(day, month, year) Cost.new(@name, @value_of_the_parcels).in_date(date) end end |
#value ⇒ Object
69 70 71 |
# File 'lib/financial/parcels.rb', line 69 def value @value_of_the_parcels * @number end |