Class: TimeKeeper::Parser::Base
- Inherits:
-
Object
- Object
- TimeKeeper::Parser::Base
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/time_keeper/parser/base.rb
Constant Summary collapse
- TIME_FORMAT_REGEX =
/^((\d){1}|(\d){2})((:(\d){2}){1})?([ ])*(am|pm)?$/i
Instance Attribute Summary collapse
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#min ⇒ Object
Returns the value of attribute min.
-
#time_str ⇒ Object
Returns the value of attribute time_str.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(time_str) ⇒ Base
constructor
A new instance of Base.
- #parse ⇒ Object
Constructor Details
#initialize(time_str) ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/time_keeper/parser/base.rb', line 14 def initialize(time_str) @time_str = time_str raise "#{time_str} is not a valid time" unless self.valid? end |
Instance Attribute Details
#hour ⇒ Object
Returns the value of attribute hour.
4 5 6 |
# File 'lib/time_keeper/parser/base.rb', line 4 def hour @hour end |
#min ⇒ Object
Returns the value of attribute min.
4 5 6 |
# File 'lib/time_keeper/parser/base.rb', line 4 def min @min end |
#time_str ⇒ Object
Returns the value of attribute time_str.
4 5 6 |
# File 'lib/time_keeper/parser/base.rb', line 4 def time_str @time_str end |
Class Method Details
.build(time_in_str) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/time_keeper/parser/base.rb', line 19 def self.build(time_in_str) if self.meridian_format?(time_in_str) TimeKeeper::Parser::Meridian.new(time_in_str) else TimeKeeper::Parser::Military.new(time_in_str) end end |
.meridian_format?(time_in_str) ⇒ Boolean
31 32 33 |
# File 'lib/time_keeper/parser/base.rb', line 31 def self.meridian_format?(time_in_str) time_in_str.downcase =~ /(am|pm)/ end |
Instance Method Details
#parse ⇒ Object
27 28 29 |
# File 'lib/time_keeper/parser/base.rb', line 27 def parse raise NotImplementedError end |