Class: Datte::Dattetime
- Inherits:
-
Object
- Object
- Datte::Dattetime
- Defined in:
- lib/datte/dattetime.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ force_update: false, level: 1 }
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#after(md) ⇒ Object
何年後、何ヶ月後、何日後, 何時間後, 何分後.
-
#initialize(options = {}) ⇒ Dattetime
constructor
A new instance of Dattetime.
- #to_datetime ⇒ Object
-
#update_date(md, options = @options) ⇒ Object
年か月か日を更新.
-
#update_time(md, options = @options) ⇒ Object
時か分を更新.
Constructor Details
#initialize(options = {}) ⇒ Dattetime
Returns a new instance of Dattetime.
11 12 13 14 |
# File 'lib/datte/dattetime.rb', line 11 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() @date = DateTime.now end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
9 10 11 |
# File 'lib/datte/dattetime.rb', line 9 def day @day end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
9 10 11 |
# File 'lib/datte/dattetime.rb', line 9 def hour @hour end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/datte/dattetime.rb', line 9 def min @min end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
9 10 11 |
# File 'lib/datte/dattetime.rb', line 9 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
9 10 11 |
# File 'lib/datte/dattetime.rb', line 9 def year @year end |
Instance Method Details
#after(md) ⇒ Object
何年後、何ヶ月後、何日後, 何時間後, 何分後
37 38 39 40 41 42 43 |
# File 'lib/datte/dattetime.rb', line 37 def after(md) @date >> (md[:year].to_i * 12) if md.matched?(:year) # 何年後 @date >> md[:month].to_i if md.matched?(:month) # 何ヶ月後 @date + md[:day].to_i if md.matched?(:day) # 何日後 @date + Rational(md[:hour].to_i, 24) # 何時間後 @date + Rational(md[:hour].to_i, 24 * 60) # 何分後 end |
#to_datetime ⇒ Object
16 17 18 19 |
# File 'lib/datte/dattetime.rb', line 16 def to_datetime return nil unless check_level? DateTime.new(y, m, d, h, mi, 0) rescue nil end |
#update_date(md, options = @options) ⇒ Object
年か月か日を更新
22 23 24 25 26 27 |
# File 'lib/datte/dattetime.rb', line 22 def update_date(md, = @options) op = @options[:force_update] ? '=' : '||=' eval("@year #{op} year!(md)") eval("@month #{op} month!(md)") eval("@day #{op} day!(md)") end |
#update_time(md, options = @options) ⇒ Object
時か分を更新
30 31 32 33 34 |
# File 'lib/datte/dattetime.rb', line 30 def update_time(md, = @options) op = @options[:force_update] ? '=' : '||=' eval("@hour #{op} hour!(md)") eval("@min #{op} min!(md)") end |