Class: OpeningHoursConverter::Token
- Inherits:
-
Object
- Object
- OpeningHoursConverter::Token
show all
- Includes:
- Constants
- Defined in:
- lib/opening_hours_converter/token.rb
Constant Summary
Constants included
from Constants
Constants::DAYS, Constants::DAYS_MAX, Constants::EASTER_WEEKDAY, Constants::IRL_DAYS, Constants::IRL_MONTHS, Constants::MINUTES_MAX, Constants::MONTH_END_DAY, Constants::OSM_DAYS, Constants::OSM_DAYS_ABBREVIATIONS, Constants::OSM_MONTHS, Constants::PH_WEEKDAY, Constants::YEAR_DAYS_MAX
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(value, type, start_index, made_from = []) ⇒ Token
Returns a new instance of Token.
10
11
12
13
14
15
|
# File 'lib/opening_hours_converter/token.rb', line 10
def initialize(value, type, start_index, made_from = [])
@value = value
@type = type
@start_index = start_index
@made_from = made_from
end
|
Instance Attribute Details
#made_from ⇒ Object
Returns the value of attribute made_from.
7
8
9
|
# File 'lib/opening_hours_converter/token.rb', line 7
def made_from
@made_from
end
|
#start_index ⇒ Object
Returns the value of attribute start_index.
8
9
10
|
# File 'lib/opening_hours_converter/token.rb', line 8
def start_index
@start_index
end
|
#type ⇒ Object
Returns the value of attribute type.
7
8
9
|
# File 'lib/opening_hours_converter/token.rb', line 7
def type
@type
end
|
#value ⇒ Object
Returns the value of attribute value.
8
9
10
|
# File 'lib/opening_hours_converter/token.rb', line 8
def value
@value
end
|
Instance Method Details
#closed? ⇒ Boolean
84
85
86
|
# File 'lib/opening_hours_converter/token.rb', line 84
def closed?
string? && @value.downcase == 'closed'
end
|
#closing_square_bracket? ⇒ Boolean
120
121
122
|
# File 'lib/opening_hours_converter/token.rb', line 120
def closing_square_bracket?
@type == :closing_square_bracket
end
|
#colon? ⇒ Boolean
108
109
110
|
# File 'lib/opening_hours_converter/token.rb', line 108
def colon?
@type == :colon
end
|
#comma? ⇒ Boolean
100
101
102
|
# File 'lib/opening_hours_converter/token.rb', line 100
def comma?
@type == :comma
end
|
#day_unit? ⇒ Boolean
The unit of a day offset ("easter +1 day", "PH -2 days").
68
69
70
|
# File 'lib/opening_hours_converter/token.rb', line 68
def day_unit?
string? && %w[day days].include?(@value.downcase)
end
|
#easter? ⇒ Boolean
63
64
65
|
# File 'lib/opening_hours_converter/token.rb', line 63
def easter?
string? && @value.downcase == 'easter'
end
|
#hyphen? ⇒ Boolean
96
97
98
|
# File 'lib/opening_hours_converter/token.rb', line 96
def hyphen?
@type == :hyphen
end
|
#integer? ⇒ Boolean
92
93
94
|
# File 'lib/opening_hours_converter/token.rb', line 92
def integer?
@type == :integer
end
|
#month? ⇒ Boolean
31
32
33
|
# File 'lib/opening_hours_converter/token.rb', line 31
def month?
string? && OSM_MONTHS.any? { |day| day.downcase == @value.downcase }
end
|
#monthday? ⇒ Boolean
49
50
51
52
|
# File 'lib/opening_hours_converter/token.rb', line 49
def monthday?
integer? && @value.to_i <= 31 && @value.to_i >= 1
end
|
#off? ⇒ Boolean
72
73
74
|
# File 'lib/opening_hours_converter/token.rb', line 72
def off?
string? && @value.downcase == 'off'
end
|
#open? ⇒ Boolean
80
81
82
|
# File 'lib/opening_hours_converter/token.rb', line 80
def open?
string? && @value.downcase == 'open'
end
|
#opening_square_bracket? ⇒ Boolean
116
117
118
|
# File 'lib/opening_hours_converter/token.rb', line 116
def opening_square_bracket?
@type == :opening_square_bracket
end
|
#public_holiday? ⇒ Boolean
59
60
61
|
# File 'lib/opening_hours_converter/token.rb', line 59
def public_holiday?
string? && @value.downcase == 'ph'
end
|
#quote? ⇒ Boolean
104
105
106
|
# File 'lib/opening_hours_converter/token.rb', line 104
def quote?
@type == :quote
end
|
#slash? ⇒ Boolean
112
113
114
|
# File 'lib/opening_hours_converter/token.rb', line 112
def slash?
@type == :slash
end
|
#string? ⇒ Boolean
88
89
90
|
# File 'lib/opening_hours_converter/token.rb', line 88
def string?
@type == :string
end
|
#time? ⇒ Boolean
54
55
56
57
|
# File 'lib/opening_hours_converter/token.rb', line 54
def time?
integer? && @value.to_i < 60 && @value.to_i >= 0
end
|
#to_s ⇒ Object
17
18
19
|
# File 'lib/opening_hours_converter/token.rb', line 17
def to_s
"Token(value: #{@value}, type: #{@type}, start_index: #{@start_index})"
end
|
#unknown? ⇒ Boolean
76
77
78
|
# File 'lib/opening_hours_converter/token.rb', line 76
def unknown?
string? && @value.downcase == 'unknown'
end
|
#week? ⇒ Boolean
35
36
37
|
# File 'lib/opening_hours_converter/token.rb', line 35
def week?
string? && @value.downcase == 'week'
end
|
#week_index? ⇒ Boolean
39
40
41
42
|
# File 'lib/opening_hours_converter/token.rb', line 39
def week_index?
integer? && @value.to_i <= 53 && @value.to_i >= 1
end
|
#weekday? ⇒ Boolean
25
26
27
28
29
|
# File 'lib/opening_hours_converter/token.rb', line 25
def weekday?
return false unless string?
(OSM_DAYS + OSM_DAYS_ABBREVIATIONS).any? { |day| day.downcase == @value.downcase }
end
|
#weekday_modifier? ⇒ Boolean
44
45
46
47
|
# File 'lib/opening_hours_converter/token.rb', line 44
def weekday_modifier?
integer? && (@value.to_i <= 5 && @value.to_i >= 1) || @value.to_i == -1
end
|
#year? ⇒ Boolean
21
22
23
|
# File 'lib/opening_hours_converter/token.rb', line 21
def year?
integer? && @value.length == 4
end
|