structr 0.0.2 → 0.0.3
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/README.rdoc +6 -5
- data/Rakefile +15 -0
- data/VERSION +1 -1
- data/examples/top.rb +2 -2
- data/lib/structr.rb +5 -4
- data/structr.gemspec +1 -1
- data/test/helper.rb +1 -0
- data/test/test_field_descriptor.rb +1 -1
- data/test/test_structr.rb +7 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -15,11 +15,11 @@ Inspired by ROXML http://github.com/Empact/roxml/tree/master
|
|
15
15
|
class Top
|
16
16
|
include Structr
|
17
17
|
|
18
|
-
converter :load do |
|
18
|
+
converter :load do |one, five, fifteen|
|
19
19
|
Load.new(one.to_f, five.to_f, fifteen.to_f)
|
20
20
|
end
|
21
21
|
|
22
|
-
converter :process do |
|
22
|
+
converter :process do |pid, user|
|
23
23
|
ProcessItem.new(pid.to_i, user)
|
24
24
|
end
|
25
25
|
|
@@ -61,10 +61,11 @@ Inspired by ROXML http://github.com/Empact/roxml/tree/master
|
|
61
61
|
|
62
62
|
== Installation
|
63
63
|
|
64
|
-
=== Gem
|
64
|
+
=== Gem via gemcutter
|
65
65
|
|
66
|
-
gem
|
67
|
-
gem
|
66
|
+
gem install gemcutter
|
67
|
+
gem tumble
|
68
|
+
gem install structr
|
68
69
|
|
69
70
|
== Authors:
|
70
71
|
* Peter Suschlik
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'rake'
|
2
3
|
require 'rake/testtask'
|
3
4
|
require 'rake/rdoctask'
|
@@ -32,6 +33,20 @@ Rake::TestTask.new(:test) do |test|
|
|
32
33
|
test.verbose = true
|
33
34
|
end
|
34
35
|
|
36
|
+
namespace :test do
|
37
|
+
desc "Run all tests on multiple ruby versions (requires rvm)"
|
38
|
+
task(:portability) do
|
39
|
+
%w(1.8.6 1.8.7 ree 1.9.1 1.9.2 jruby).each do |version|
|
40
|
+
system <<-BASH
|
41
|
+
bash -c 'source ~/.rvm/scripts/rvm;
|
42
|
+
rvm #{version};
|
43
|
+
echo "--------- v#{version} ----------\n";
|
44
|
+
rake -s test'
|
45
|
+
BASH
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
35
50
|
# RDoc
|
36
51
|
Rake::RDocTask.new do |rd|
|
37
52
|
rd.title = "Parse plain text with Ruby classes"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/examples/top.rb
CHANGED
@@ -6,11 +6,11 @@ ProcessItem = Struct.new(:pid, :user)
|
|
6
6
|
class Top
|
7
7
|
include Structr
|
8
8
|
|
9
|
-
converter :load do |
|
9
|
+
converter :load do |one, five, fifteen|
|
10
10
|
Load.new(one.to_f, five.to_f, fifteen.to_f)
|
11
11
|
end
|
12
12
|
|
13
|
-
converter :process do |
|
13
|
+
converter :process do |pid, user|
|
14
14
|
ProcessItem.new(pid.to_i, user)
|
15
15
|
end
|
16
16
|
|
data/lib/structr.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'date'
|
1
2
|
|
2
3
|
module Structr
|
3
4
|
|
@@ -8,10 +9,10 @@ module Structr
|
|
8
9
|
module ClassMethods
|
9
10
|
|
10
11
|
Converter = {
|
11
|
-
:int => proc {|m| m.to_i },
|
12
|
-
:float => proc {|m| m.to_f },
|
13
|
-
:date => proc {|m| Date.parse(m) },
|
14
|
-
:string => proc {|m| m },
|
12
|
+
:int => proc { |m| m.to_i },
|
13
|
+
:float => proc { |m| m.to_f },
|
14
|
+
:date => proc { |m| ::Date.parse(m) },
|
15
|
+
:string => proc { |m| m.to_s },
|
15
16
|
}
|
16
17
|
|
17
18
|
def field(name, regexp, options={}, &block)
|
data/structr.gemspec
CHANGED
data/test/helper.rb
CHANGED
@@ -24,7 +24,7 @@ context Struct::FieldDefinition do
|
|
24
24
|
|
25
25
|
asserts("match without block") { topic.match("costs 23,42$") }.equals([["23", "42"]])
|
26
26
|
asserts("matech with block") do
|
27
|
-
topic.block = proc {|
|
27
|
+
topic.block = proc { |dollar, cents| dollar.to_i * 100 + cents.to_i }
|
28
28
|
topic.match("costs 23,42$")
|
29
29
|
end.equals([2342])
|
30
30
|
end
|
data/test/test_structr.rb
CHANGED
@@ -89,6 +89,13 @@ context Structr do
|
|
89
89
|
asserts("raises NoMethodError for #{field_name}") { topic.send(field_name, %r{}) }.raises(NoMethodError)
|
90
90
|
end
|
91
91
|
|
92
|
+
context "default" do
|
93
|
+
asserts("int converts to_i") { topic.converter(:int).call("2") }.equals(2)
|
94
|
+
asserts("int converts to_f") { topic.converter(:float).call("2") }.equals(2.0)
|
95
|
+
asserts("int converts to Date") { topic.converter(:date).call("2009-09-09").to_s }.equals("2009-09-09")
|
96
|
+
asserts("int converts to String") { topic.converter(:string).call(2) }.equals("2")
|
97
|
+
end
|
98
|
+
|
92
99
|
context "added" do
|
93
100
|
setup do
|
94
101
|
topic.converter(:proced, proc { |p| p })
|