texp 0.0.3 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +36 -2
- data/README +92 -0
- data/Rakefile +26 -1
- data/TAGS +369 -0
- data/lib/texp.rb +6 -1
- data/lib/texp/base.rb +139 -10
- data/lib/texp/builder.rb +254 -0
- data/lib/texp/day_interval.rb +19 -15
- data/lib/texp/day_of_month.rb +1 -7
- data/lib/texp/day_of_week.rb +1 -7
- data/lib/texp/dsl.rb +338 -0
- data/lib/texp/errors.rb +18 -0
- data/lib/texp/every_day.rb +1 -5
- data/lib/texp/logic.rb +16 -40
- data/lib/texp/month.rb +1 -6
- data/lib/texp/operators.rb +53 -0
- data/lib/texp/parse.rb +9 -27
- data/lib/texp/time_ext.rb +7 -0
- data/lib/texp/version.rb +3 -0
- data/lib/texp/week.rb +1 -7
- data/lib/texp/window.rb +30 -12
- data/lib/texp/year.rb +1 -6
- data/test/texp/base_test.rb +82 -0
- data/test/texp/day_interval_test.rb +24 -12
- data/test/texp/day_of_month_test.rb +10 -10
- data/test/texp/day_of_week_test.rb +14 -14
- data/test/texp/dsl_test.rb +288 -0
- data/test/texp/every_day_test.rb +1 -1
- data/test/texp/ext_test.rb +3 -3
- data/test/texp/logic_test.rb +18 -18
- data/test/texp/month_test.rb +3 -3
- data/test/texp/operators_test.rb +52 -0
- data/test/texp/parse_test.rb +39 -39
- data/test/texp/time_ext_test.rb +8 -0
- data/test/texp/week_test.rb +19 -19
- data/test/texp/window_test.rb +41 -12
- data/test/texp/year_test.rb +7 -7
- data/test/texp_tests.rb +27 -0
- metadata +14 -6
- data/lib/texp/core.rb +0 -41
- data/lib/texp/hash_builder.rb +0 -44
- data/test/texp/hash_test.rb +0 -26
- data/test/texp/logic_text_test.rb +0 -0
data/lib/texp/core.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module TExp
|
2
|
-
class << self
|
3
|
-
def from_db(string)
|
4
|
-
stack = []
|
5
|
-
string.split(":").each do |code|
|
6
|
-
case code
|
7
|
-
when /^\d+$/
|
8
|
-
stack.push(code.to_i)
|
9
|
-
when /^\d\d\d\d-\d\d-\d\d$/
|
10
|
-
stack.push(Date.parse(code))
|
11
|
-
when 'x'
|
12
|
-
n = stack.pop
|
13
|
-
args = []
|
14
|
-
n.times do args.unshift(stack.pop) end
|
15
|
-
stack.push args
|
16
|
-
when 'e'
|
17
|
-
stack.push TExp::EveryDay.new
|
18
|
-
when 'm'
|
19
|
-
stack.push TExp::DayOfMonth.new(stack.pop)
|
20
|
-
when 'w'
|
21
|
-
stack.push TExp::DayOfWeek.new(stack.pop)
|
22
|
-
when 'i'
|
23
|
-
interval = stack.pop
|
24
|
-
date = stack.pop
|
25
|
-
stack.push TExp::DayInterval.new(date, interval)
|
26
|
-
when 'a'
|
27
|
-
right = stack.pop
|
28
|
-
left = stack.pop
|
29
|
-
stack.push(TExp::And.new(left, right))
|
30
|
-
when 'o'
|
31
|
-
right = stack.pop
|
32
|
-
left = stack.pop
|
33
|
-
stack.push(TExp::Or.new(left, right))
|
34
|
-
else
|
35
|
-
fail "Unknown TExp DB Code"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
stack.pop
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/texp/hash_builder.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module TExp
|
2
|
-
|
3
|
-
# Build a temporal expression hash representation
|
4
|
-
#
|
5
|
-
# Usage:
|
6
|
-
#
|
7
|
-
# builder = HashBuilder.new(encoding_token)
|
8
|
-
# builder.with(the_first_paramter)
|
9
|
-
# builder.with(the_next_parameter)
|
10
|
-
# hash = builder.hash
|
11
|
-
#
|
12
|
-
class HashBuilder
|
13
|
-
# Convert the builder to a hash.
|
14
|
-
attr_reader :hash
|
15
|
-
|
16
|
-
# Create a temporal expression params hash builder.
|
17
|
-
def initialize(type)
|
18
|
-
@type = type
|
19
|
-
@hash = { 'type' => type }
|
20
|
-
@args = 0
|
21
|
-
end
|
22
|
-
|
23
|
-
# Add an argument to the hash.
|
24
|
-
def with(arg)
|
25
|
-
@args += 1
|
26
|
-
@hash["#{@type}#{@args}"] = simplify(arg)
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
# Simplify the value to be placed in the hash. Essentially we
|
31
|
-
# want only strings and lists.
|
32
|
-
def simplify(value)
|
33
|
-
case value
|
34
|
-
when String
|
35
|
-
value
|
36
|
-
when Array
|
37
|
-
value.map { |item| simplify(item) }
|
38
|
-
else
|
39
|
-
value.to_s
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
data/test/texp/hash_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'date'
|
5
|
-
require 'texp'
|
6
|
-
|
7
|
-
######################################################################
|
8
|
-
# TODO: This test is incomplete.
|
9
|
-
#
|
10
|
-
class ToHashTest < Test::Unit::TestCase
|
11
|
-
def test_to_hash
|
12
|
-
assert_hash '2008-02-14,2i', 'type' => 'i', 'i1' => '2008-02-14', 'i2' => '2'
|
13
|
-
assert_hash '[0,2]w', 'type' => 'w', 'w1' => ['0', '2']
|
14
|
-
assert_hash '[1,15]d', 'type' => 'd', 'd1' => ['1', '15']
|
15
|
-
assert_hash '[1,2,-1]k', 'type' => 'k', 'k1' => ['1', '2', '-1']
|
16
|
-
assert_hash '[1,3]m', 'type' => 'm', 'm1' => ['1', '3']
|
17
|
-
assert_hash '[2008,2010]y', 'type' => 'y', 'y1' => ['2008', '2010']
|
18
|
-
assert_hash 'e', 'type' => 'e'
|
19
|
-
end
|
20
|
-
|
21
|
-
def assert_hash(texp, hash)
|
22
|
-
assert_equal hash, TExp.parse(texp).to_hash, "should match for '#{texp}'"
|
23
|
-
# assert_equal texp, TExp.from_params('1' => hash).to_s
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
File without changes
|