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::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(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
#closing_square_bracket? ⇒ Boolean
93
94
95
|
# File 'lib/opening_hours_converter/token.rb', line 93
def closing_square_bracket?
@type == :closing_square_bracket
end
|
#colon? ⇒ Boolean
81
82
83
|
# File 'lib/opening_hours_converter/token.rb', line 81
def colon?
@type == :colon
end
|
#comma? ⇒ Boolean
73
74
75
|
# File 'lib/opening_hours_converter/token.rb', line 73
def comma?
@type == :comma
end
|
#hyphen? ⇒ Boolean
69
70
71
|
# File 'lib/opening_hours_converter/token.rb', line 69
def hyphen?
@type == :hyphen
end
|
#integer? ⇒ Boolean
65
66
67
|
# File 'lib/opening_hours_converter/token.rb', line 65
def integer?
@type == :integer
end
|
#month? ⇒ Boolean
25
26
27
|
# File 'lib/opening_hours_converter/token.rb', line 25
def month?
string? && OSM_MONTHS.any? { |day| day == @value }
end
|
#monthday? ⇒ Boolean
43
44
45
46
|
# File 'lib/opening_hours_converter/token.rb', line 43
def monthday?
integer? && @value.to_i <= 31 && @value.to_i >= 1
end
|
#off? ⇒ Boolean
57
58
59
|
# File 'lib/opening_hours_converter/token.rb', line 57
def off?
string? && @value.downcase == 'off'
end
|
#opening_square_bracket? ⇒ Boolean
89
90
91
|
# File 'lib/opening_hours_converter/token.rb', line 89
def opening_square_bracket?
@type == :opening_square_bracket
end
|
#public_holiday? ⇒ Boolean
53
54
55
|
# File 'lib/opening_hours_converter/token.rb', line 53
def public_holiday?
string? && @value.downcase == 'ph'
end
|
#quote? ⇒ Boolean
77
78
79
|
# File 'lib/opening_hours_converter/token.rb', line 77
def quote?
@type == :quote
end
|
#slash? ⇒ Boolean
85
86
87
|
# File 'lib/opening_hours_converter/token.rb', line 85
def slash?
@type == :slash
end
|
#string? ⇒ Boolean
61
62
63
|
# File 'lib/opening_hours_converter/token.rb', line 61
def string?
@type == :string
end
|
#time? ⇒ Boolean
48
49
50
51
|
# File 'lib/opening_hours_converter/token.rb', line 48
def time?
integer? && @value.to_i < 60 && @value.to_i >= 0
end
|
#week? ⇒ Boolean
29
30
31
|
# File 'lib/opening_hours_converter/token.rb', line 29
def week?
string? && @value == 'week'
end
|
#week_index? ⇒ Boolean
33
34
35
36
|
# File 'lib/opening_hours_converter/token.rb', line 33
def week_index?
integer? && @value.to_i <= 53 && @value.to_i >= 1
end
|
#weekday? ⇒ Boolean
21
22
23
|
# File 'lib/opening_hours_converter/token.rb', line 21
def weekday?
string? && OSM_DAYS.any? { |day| day == @value }
end
|
#weekday_modifier? ⇒ Boolean
38
39
40
41
|
# File 'lib/opening_hours_converter/token.rb', line 38
def weekday_modifier?
integer? && (@value.to_i <= 5 && @value.to_i >= 1) || @value.to_i == -1
end
|
#year? ⇒ Boolean
17
18
19
|
# File 'lib/opening_hours_converter/token.rb', line 17
def year?
integer? && @value.length == 4
end
|