Class: PagSeguro::DayOfYear

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/pag_seguro/day_of_year.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DayOfYear

Returns a new instance of DayOfYear.



14
15
16
17
# File 'lib/pag_seguro/day_of_year.rb', line 14

def initialize(options = {})
  @day = options[:day]
  @month = options[:month]
end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



12
13
14
# File 'lib/pag_seguro/day_of_year.rb', line 12

def day
  @day
end

#monthObject

Returns the value of attribute month.



12
13
14
# File 'lib/pag_seguro/day_of_year.rb', line 12

def month
  @month
end

Instance Method Details

#<=>(other_day_of_the_year) ⇒ Object



30
31
32
33
34
# File 'lib/pag_seguro/day_of_year.rb', line 30

def <=>(other_day_of_the_year)
  return  1 if @month > other_day_of_the_year.month
  return -1 if @month < other_day_of_the_year.month
  @day <=> other_day_of_the_year.day
end

#to_sObject



19
20
21
22
# File 'lib/pag_seguro/day_of_year.rb', line 19

def to_s
  raise Error::InvalidDayOfYear.new(self) unless valid?
  "#{"%02d" % @month}-#{"%02d" % @day}"
end

#valid?Boolean

very simple date validation, just to smoke test possible errors of switching day with month

Returns:

  • (Boolean)


26
27
28
# File 'lib/pag_seguro/day_of_year.rb', line 26

def valid?
  @day < 31 && @month < 12
end