Class: OpeningHoursConverter::TokensHandler

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/opening_hours_converter/tokens_handler.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(tokens) ⇒ TokensHandler

Returns a new instance of TokensHandler.



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

def initialize(tokens)
  @unhandled_tokens = tokens
  @index = 0
  @tokens = []

  handle_tokens
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



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

def tokens
  @tokens
end

Instance Method Details

#handle_tokensObject



17
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/opening_hours_converter/tokens_handler.rb', line 17

def handle_tokens
  while current_token?
    if current_token.year?
      @tokens << handle_year
      next
    end

    if current_token.month?
      @tokens << handle_month
      next
    end

    if current_token.week?
      @tokens << handle_week
      next
    end

    if current_token.weekday?
      @tokens << handle_weekday
      next
    end

    if current_token_is_time?
      @tokens << handle_time
      next
    end

    if current_token.public_holiday?
      @tokens << handle_public_holiday
      next
    end

    if current_token_is_all_time?
      @tokens << handle_all_time
      next
    end

    if current_token.off?
      @tokens << handle_off
      next
    end

    if current_token.quote?
      @tokens << handle_quote
      next
    end

    if current_token.comma?
      # catches "Mo off, Tu 10:00-20:00"
      @index += 1
      next
    end

    if current_token.colon?
      # catches "Dec: "
      @index += 1
      next
    end

    raise ParseError, "can't read current token #{current_token}"
  end
end