texp 0.0.3 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -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