Class: TimeKeeper::Parser::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/time_keeper/parser/base.rb

Direct Known Subclasses

Meridian, Military

Constant Summary collapse

TIME_FORMAT_REGEX =
/^((\d){1}|(\d){2})((:(\d){2}){1})?([ ])*(am|pm)?$/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hourObject

Returns the value of attribute hour.



4
5
6
# File 'lib/time_keeper/parser/base.rb', line 4

def hour
  @hour
end

#minObject

Returns the value of attribute min.



4
5
6
# File 'lib/time_keeper/parser/base.rb', line 4

def min
  @min
end

#time_strObject

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

Returns:

  • (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

#parseObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/time_keeper/parser/base.rb', line 27

def parse
  raise NotImplementedError
end