Class: Datte::Dattetime

Inherits:
Object
  • Object
show all
Defined in:
lib/datte/dattetime.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  force_update: false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Dattetime

Returns a new instance of Dattetime.



10
11
12
13
# File 'lib/datte/dattetime.rb', line 10

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @date = Date.today
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def day
  @day
end

#hourObject (readonly)

Returns the value of attribute hour.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def hour
  @hour
end

#minObject (readonly)

Returns the value of attribute min.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def min
  @min
end

#monthObject (readonly)

Returns the value of attribute month.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def month
  @month
end

#secObject (readonly)

Returns the value of attribute sec.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def sec
  @sec
end

#yearObject (readonly)

Returns the value of attribute year.



8
9
10
# File 'lib/datte/dattetime.rb', line 8

def year
  @year
end

Instance Method Details

#after_date(year, month, day) ⇒ Object

何年後、何ヶ月後、何日後



36
37
# File 'lib/datte/dattetime.rb', line 36

def after_date(year, month, day)
end

#after_time(hour, min) ⇒ Object

何時間後、何分後



40
41
# File 'lib/datte/dattetime.rb', line 40

def after_time(hour, min)
end

#to_datetimeObject



19
20
21
# File 'lib/datte/dattetime.rb', line 19

def to_datetime
  DateTime.new(@year, @month, @day, 12, 0, 0) rescue nil
end

#to_sObject



15
16
17
# File 'lib/datte/dattetime.rb', line 15

def to_s
  @date.to_s
end

#update_date(md, options = @options) ⇒ Object

年か月か日を更新



24
25
26
27
28
29
# File 'lib/datte/dattetime.rb', line 24

def update_date(md, options = @options)
  op = @options[:force_update] ? '=' : '||='
  eval("@year #{op} year!(md)")
  eval("@month #{op} month!(md)")
  eval("@day #{op} day!(md)")
end

#update_time(hour, min) ⇒ Object

時か分を更新



32
33
# File 'lib/datte/dattetime.rb', line 32

def update_time(hour, min)
end