structr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 |(one, five, fifteen)|
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 |(pid, user)|
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 source -a http://gems.github.com
67
- gem install splattael-structr
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.2
1
+ 0.0.3
@@ -6,11 +6,11 @@ ProcessItem = Struct.new(:pid, :user)
6
6
  class Top
7
7
  include Structr
8
8
 
9
- converter :load do |(one, five, fifteen)|
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 |(pid, user)|
13
+ converter :process do |pid, user|
14
14
  ProcessItem.new(pid.to_i, user)
15
15
  end
16
16
 
@@ -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)
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{structr}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Suschlik"]
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'structr'
2
3
 
3
4
  require 'riot'
@@ -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 {|(dollar, cents)| dollar.to_i * 100 + cents.to_i }
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
@@ -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 })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik