Class: BlockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/block_parser.rb

Overview

Can translate various string representations of a block (e.g. 12:40-18) into an instance of Block.

Constant Summary collapse

HALF_BLOCK_RGX =

What the start or finish part of a block may look like, e.g. “09:00”, “09”, “9”, etc

/^\d{1,2}:?\d{0,2}$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_str, day) ⇒ BlockParser

Returns a new instance of BlockParser.


14
15
16
17
# File 'lib/block_parser.rb', line 14

def initialize(block_str, day)
  @block_str = block_str
  @day = day
end

Class Method Details

.parse(block_str, day) ⇒ Object


10
11
12
# File 'lib/block_parser.rb', line 10

def self.parse(block_str, day)
  new(block_str, day).parse
end

Instance Method Details

#parseObject


19
20
21
22
# File 'lib/block_parser.rb', line 19

def parse
  prepare_block_str!
  Block.from(@block_str, @day)
end