Module: RtmTime
- Defined in:
- lib/rtm_time.rb,
lib/rtm_time/iso8601.rb,
lib/rtm_time/version.rb,
lib/rtm_time/estimate/en.rb,
lib/rtm_time/estimate/ja.rb
Defined Under Namespace
Classes: En, InvalidTime, Ja
Constant Summary collapse
- VERSION =
'0.3.0'
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.
Class Method Summary collapse
- .extended(obj) ⇒ Object
-
.iso8601(time = Time.now) ⇒ Object
convert from various object to ISO8601(UTC) string.
Instance Method Summary collapse
-
#parse(time_str) ⇒ Object
- param
-
String time_str.
-
#to_a ⇒ Object
- return
-
Array.
-
#to_h ⇒ Object
(also: #to_hash)
- return
-
Hash.
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/rtm_time.rb', line 6 def day @day end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
6 7 8 |
# File 'lib/rtm_time.rb', line 6 def hour @hour end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
6 7 8 |
# File 'lib/rtm_time.rb', line 6 def min @min end |
Class Method Details
.extended(obj) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/rtm_time.rb', line 8 def self.extended( obj ) obj.class_eval { def obj.parse( time_str ) self.new.parse( time_str ) end } end |
.iso8601(time = Time.now) ⇒ Object
convert from various object to ISO8601(UTC) string
- param
-
Object
- return
-
String
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rtm_time/iso8601.rb', line 12 def self.iso8601( time = Time.now ) t = nil case time when String t = Time.parse(time) when Integer t = Time.at(time) when Time t = time else if time.respond_to? :to_time t = time.to_time else raise InvalidTime, time end end t.utc.iso8601 if t end |
Instance Method Details
#parse(time_str) ⇒ Object
- param
-
String time_str
解釈できない場合、エラーがユーザーに feedback されるケースと単に無 視されるケースがある
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rtm_time.rb', line 22 def parse( time_str ) @day = nil @hour = nil @min = nil parsed = time_str.sub(/[PT]/, ' ').scan(/(?:([0-9\.]+)\s*([^0-9]+|\z))/u) if parsed.size > 0 # d, h, m の順番にも縛りはない parsed.each { |num, unit| assort( num, unit ) } @day = @day.to_i @min = (@min.to_i + ((@hour || 0) - @hour.to_i) * 60).round @hour = @hour.to_i end self end |
#to_a ⇒ Object
- return
-
Array
45 46 47 |
# File 'lib/rtm_time.rb', line 45 def to_a [day, hour, min] end |
#to_h ⇒ Object Also known as: to_hash
- return
-
Hash
52 53 54 |
# File 'lib/rtm_time.rb', line 52 def to_h {:day => day, :hour => hour, :min => min} end |