Class: Crntb::Field
- Inherits:
-
Object
show all
- Defined in:
- lib/crntb/field.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(field) ⇒ Field
Returns a new instance of Field.
11
12
13
|
# File 'lib/crntb/field.rb', line 11
def initialize(field)
@field = field
end
|
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
3
4
5
|
# File 'lib/crntb/field.rb', line 3
def field
@field
end
|
Class Method Details
.parse(field) ⇒ Object
6
7
8
|
# File 'lib/crntb/field.rb', line 6
def parse(field)
self.new(field).parse
end
|
Instance Method Details
#every_time? ⇒ Boolean
100
101
|
# File 'lib/crntb/field.rb', line 100
def every_time?
end
|
#expand_range(collections) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/crntb/field.rb', line 79
def expand_range(collections)
result = []
collections.each do |collection|
if collection.include?('-')
min, max = collection.split('-', 2)
for i in min..max do
result << i
end
else
result << collection
end
end
end
|
#first_to_last? ⇒ Boolean
93
94
95
|
# File 'lib/crntb/field.rb', line 93
def first_to_last?
field == '*'
end
|
#get_collection ⇒ Object
60
61
62
|
# File 'lib/crntb/field.rb', line 60
def get_collection
end
|
#get_range(value) ⇒ Object
e.g
"*/1" => ["*", "1"]
"*/1,2-4" => ["*", "1,2-4"]
67
68
69
70
71
72
73
|
# File 'lib/crntb/field.rb', line 67
def get_range(value)
if value == '*'
[field_range.first, field_range.last]
else
value.split('-')
end
end
|
#get_step(value) ⇒ Object
75
76
77
|
# File 'lib/crntb/field.rb', line 75
def get_step(value)
value.split('/')
end
|
#interpretation ⇒ Object
先頭文字列を処理
*/...
n...
それ以降はカンマ区切りでsplitして-はloop処理しての繰り返し
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
|
# File 'lib/crntb/field.rb', line 25
def interpretation
step_collections = field.split(',')
collections = []
step_collections.each do |step_collection|
step = get_step(step_collection)
if step[1] && step[1].match(/^[0-9]+$/)
step_size = step[1].to_i
else
step_size = 1
end
range = get_range(step[0])
if range.length > 1
s = range[0].to_i
e = range[1].to_i
s.step(e, step_size) { |r| collections << r }
end
end
collections.uniq.sort
result = collections.inject '' do |res, collection|
res += collection.to_s
res += ", "
end
result.slice!(result.size - 2, 2)
result
end
|
#parse ⇒ Object
15
16
17
18
19
|
# File 'lib/crntb/field.rb', line 15
def parse
return '*' if first_to_last?
interpretation
end
|
#range_time? ⇒ Boolean
97
98
|
# File 'lib/crntb/field.rb', line 97
def range_time?
end
|