Class: OpeningHoursConverter::Tokenizer

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/opening_hours_converter/tokenizer.rb

Constant Summary

Constants included from Constants

Constants::DAYS, Constants::DAYS_MAX, Constants::IRL_DAYS, Constants::IRL_MONTHS, Constants::MINUTES_MAX, Constants::MONTH_END_DAY, Constants::OSM_DAYS, Constants::OSM_MONTHS, Constants::PH_WEEKDAY, Constants::YEAR_DAYS_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opening_hours_string) ⇒ Tokenizer

Returns a new instance of Tokenizer.



9
10
11
12
13
14
15
16
# File 'lib/opening_hours_converter/tokenizer.rb', line 9

def initialize(opening_hours_string)
  @opening_hours_string = opening_hours_string
  @index = 0
  @tokens = []
  tokenize
  @tokens_handler = OpeningHoursConverter::TokensHandler.new(@tokens)
  @tokens = @tokens_handler.tokens.map(&:value)
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



7
8
9
# File 'lib/opening_hours_converter/tokenizer.rb', line 7

def tokens
  @tokens
end

Instance Method Details

#tokenizeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/opening_hours_converter/tokenizer.rb', line 18

def tokenize
  counter = 0
  while @index < @opening_hours_string.length
    raise ParseError if counter > 200
    skip_white_spaces
    @tokens << handle_string if string?

    skip_white_spaces
    @tokens << handle_integer if integer?

    skip_white_spaces
    @tokens << handle_quote if quote?

    skip_white_spaces
    @tokens << handle_slash if slash?

    skip_white_spaces
    @tokens << handle_opening_square_bracket if opening_square_bracket?

    skip_white_spaces
    @tokens << handle_closing_square_bracket if closing_square_bracket?

    skip_white_spaces
    @tokens << handle_colon if colon?

    skip_white_spaces
    @tokens << handle_comma if comma?

    skip_white_spaces
    @tokens << handle_hyphen if hyphen?
    counter += 1
  end
end