bikepoa-tools 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -4
- data/VERSION +1 -1
- data/bikepoa-tools.gemspec +1 -1
- data/lib/bikepoa/helpers.rb +8 -5
- data/spec/helpers_spec.rb +34 -14
- metadata +1 -1
data/README.md
CHANGED
@@ -4,14 +4,33 @@
|
|
4
4
|
bikepoa-tools
|
5
5
|
=============
|
6
6
|
|
7
|
-
|
7
|
+
Gem containing a simple API to interact with information systems of [BikePOA](http://mobilicidade.com.br/bikepoa/), the
|
8
8
|
bicycle-sharing program of Porto Alegre, Brazil.
|
9
9
|
|
10
|
+
installation
|
11
|
+
============
|
12
|
+
|
13
|
+
To install the version that was released as a gem most recently, simply use
|
14
|
+
|
15
|
+
```
|
16
|
+
~$ gem install bikepoa-tools
|
17
|
+
```
|
18
|
+
|
19
|
+
If you want to be on top of things and use the latest github version, use
|
20
|
+
|
21
|
+
```
|
22
|
+
~$ git clone git@github.com:fmobus/bikepoa-tools.git
|
23
|
+
~$ cd bikepoa-tools
|
24
|
+
~/bikepoa-tools$ rake build
|
25
|
+
~/bikepoa-tools$ rake install
|
26
|
+
```
|
27
|
+
|
28
|
+
|
10
29
|
usage
|
11
30
|
=====
|
12
31
|
|
13
32
|
```ruby
|
14
|
-
>>> require '
|
33
|
+
>>> require 'bikepoa'
|
15
34
|
>>> client = BikePOA::Client.new
|
16
35
|
>>> client.stations
|
17
36
|
[
|
@@ -38,9 +57,8 @@ usage
|
|
38
57
|
]
|
39
58
|
```
|
40
59
|
|
41
|
-
|
60
|
+
Wishlist
|
42
61
|
====
|
43
62
|
|
44
|
-
* Package it as a gem
|
45
63
|
* Add latitude and longitude to Station
|
46
64
|
* Less crude interface in Station
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bikepoa-tools.gemspec
CHANGED
data/lib/bikepoa/helpers.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
module BikePOA
|
2
2
|
module Helpers
|
3
3
|
module ForceField
|
4
|
+
FORCED_FIELDS = {}
|
4
5
|
def self.included(base)
|
5
6
|
base.send :extend, ClassMethods
|
6
7
|
end
|
7
8
|
|
9
|
+
def []=(property, value)
|
10
|
+
transform = FORCED_FIELDS[property.to_sym]
|
11
|
+
value = transform.call(value) if transform
|
12
|
+
super(property, value)
|
13
|
+
end
|
14
|
+
|
8
15
|
module ClassMethods
|
9
16
|
def force_integer(field)
|
10
|
-
|
11
|
-
define_method("#{field}=".to_sym) do |value|
|
12
|
-
self.[]=(field, Integer(value))
|
13
|
-
end
|
14
|
-
end
|
17
|
+
FORCED_FIELDS[field.to_sym] = lambda { |value| Integer(value) }
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -1,22 +1,42 @@
|
|
1
1
|
|
2
2
|
describe BikePOA::Helpers::ForceField do
|
3
|
-
|
4
|
-
include BikePOA::Helpers::ForceField
|
5
|
-
property :number
|
6
|
-
force_integer :number
|
7
|
-
end
|
3
|
+
describe 'force integer' do
|
8
4
|
|
9
|
-
|
5
|
+
class DummySubject < Hashie::Dash
|
6
|
+
include BikePOA::Helpers::ForceField
|
7
|
+
property :normal
|
8
|
+
property :number
|
10
9
|
|
11
|
-
|
12
|
-
it "accepts any value that is castable to integer" do
|
13
|
-
expect { dummy.number = '42' }.to_not raise_error(ArgumentError)
|
14
|
-
expect { dummy.number = 42 }.to_not raise_error(ArgumentError)
|
15
|
-
expect { dummy.number = 42.0 }.to_not raise_error(ArgumentError)
|
10
|
+
force_integer :number
|
16
11
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
|
13
|
+
describe "when setting property directly" do
|
14
|
+
let(:dummy) { DummySubject.new }
|
15
|
+
|
16
|
+
it "accepts any value that is castable to integer" do
|
17
|
+
expect { dummy.number = '42' }.to_not raise_error(ArgumentError)
|
18
|
+
expect { dummy.number = 42 }.to_not raise_error(ArgumentError)
|
19
|
+
expect { dummy.number = 42.0 }.to_not raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
it "raises when the value is not castable to integer" do
|
22
|
+
expect { dummy.number = "abc" }.to raise_error(ArgumentError)
|
23
|
+
expect { dummy.number = "a12" }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
it 'lets you put anything into non-forced fields' do
|
26
|
+
expect { DummySubject.new(normal: 'abc1123') }.to_not raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when loading the Dash from a hash" do
|
31
|
+
it 'accepts values castable to integer' do
|
32
|
+
expect { DummySubject.new(number: '678') }.to_not raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
it "raises when one of the forced-fields is invalid" do
|
35
|
+
expect { DummySubject.new(number: "abc") }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
it 'lets you put anything into non-forced fields' do
|
38
|
+
expect { DummySubject.new(normal: 'abc1123') }.to_not raise_error
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|