Class: Blertr::Message
- Inherits:
-
Object
- Object
- Blertr::Message
- Defined in:
- lib/blertr/message.rb
Constant Summary collapse
- SECS_IN_MIN =
60- MIN_IN_HOUR =
60- SEC_RANGE =
(2..59)
- ONE_MIN_RANGE =
(60..119)
- MINS_RANGE =
(120..(SECS_IN_MIN * MIN_IN_HOUR - 1))
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#seconds ⇒ Object
Returns the value of attribute seconds.
Instance Method Summary collapse
- #command_short_name ⇒ Object
-
#initialize(command, time) ⇒ Message
constructor
A new instance of Message.
- #time_string ⇒ Object
Constructor Details
#initialize(command, time) ⇒ Message
Returns a new instance of Message.
10 11 12 13 |
# File 'lib/blertr/message.rb', line 10 def initialize command, time self.command = command.strip self.seconds = time.to_i end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/blertr/message.rb', line 8 def command @command end |
#seconds ⇒ Object
Returns the value of attribute seconds.
8 9 10 |
# File 'lib/blertr/message.rb', line 8 def seconds @seconds end |
Instance Method Details
#command_short_name ⇒ Object
15 16 17 |
# File 'lib/blertr/message.rb', line 15 def command_short_name File.basename(self.command.split(/ /)[0]) end |
#time_string ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/blertr/message.rb', line 19 def time_string case seconds when 1 "1 second" when 0, SEC_RANGE "#{seconds} seconds" when ONE_MIN_RANGE "1 minute" when MINS_RANGE mins = seconds / SECS_IN_MIN "#{mins} minutes" else hours = (seconds.to_f / SECS_IN_MIN.to_f / MIN_IN_HOUR.to_f).round(2) if hours == 1.0 "1 hour" else "#{hours} hours" end end end |