bikepoa-tools 0.3.0 → 0.3.1
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/VERSION +1 -1
- data/bikepoa-tools.gemspec +2 -2
- data/lib/bikepoa/helpers.rb +7 -0
- data/lib/bikepoa/station.rb +3 -0
- data/spec/helpers_spec.rb +30 -7
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.1
|
data/bikepoa-tools.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "bikepoa-tools"
|
|
8
|
-
s.version = "0.3.
|
|
8
|
+
s.version = "0.3.1"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Felipe Mobus"]
|
|
12
|
-
s.date = "
|
|
12
|
+
s.date = "2013-01-18"
|
|
13
13
|
s.description = "A simple read-only API for Porto Alegre's bike rental system, bikepoa."
|
|
14
14
|
s.email = "fmobus@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/bikepoa/helpers.rb
CHANGED
|
@@ -16,6 +16,13 @@ module BikePOA
|
|
|
16
16
|
def force_integer(field)
|
|
17
17
|
FORCED_FIELDS[field.to_sym] = lambda { |value| Integer(value) }
|
|
18
18
|
end
|
|
19
|
+
|
|
20
|
+
def force_utf8(field)
|
|
21
|
+
FORCED_FIELDS[field.to_sym] = lambda do |value|
|
|
22
|
+
new_value = value.encode('utf-8','iso-8859-1')
|
|
23
|
+
(new_value.length == value.length)? new_value : value
|
|
24
|
+
end
|
|
25
|
+
end
|
|
19
26
|
end
|
|
20
27
|
end
|
|
21
28
|
end
|
data/lib/bikepoa/station.rb
CHANGED
data/spec/helpers_spec.rb
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
|
|
2
2
|
describe BikePOA::Helpers::ForceField do
|
|
3
|
-
|
|
3
|
+
class DummySubject < Hashie::Dash
|
|
4
|
+
include BikePOA::Helpers::ForceField
|
|
5
|
+
property :normal
|
|
6
|
+
property :number
|
|
7
|
+
property :name
|
|
8
|
+
|
|
9
|
+
force_integer :number
|
|
10
|
+
force_utf8 :name
|
|
11
|
+
end
|
|
4
12
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
property :normal
|
|
8
|
-
property :number
|
|
13
|
+
describe 'force utf8' do
|
|
14
|
+
let(:dummy) { DummySubject.new }
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
describe 'when setting property directly' do
|
|
17
|
+
it 'encodes a iso-8859-1 value to utf-8' do
|
|
18
|
+
dummy.name = "Jo\xE3o da Silva"
|
|
19
|
+
dummy.name.should == "Jo\xC3\xA3o da Silva"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'does not try to over-convert an utf-8 value' do
|
|
23
|
+
dummy.name = "Jo\xC3\xA3o da Silva"
|
|
24
|
+
dummy.name.should == "Jo\xC3\xA3o da Silva"
|
|
25
|
+
end
|
|
11
26
|
end
|
|
27
|
+
describe "when loading the Dash from a hash" do
|
|
28
|
+
it 'encodes an iso-8859-1 value to utf-8' do
|
|
29
|
+
expect { DummySubject.new(number: '678') }.to_not raise_error(ArgumentError)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'force integer' do
|
|
35
|
+
let(:dummy) { DummySubject.new }
|
|
12
36
|
|
|
13
37
|
describe "when setting property directly" do
|
|
14
|
-
let(:dummy) { DummySubject.new }
|
|
15
38
|
|
|
16
39
|
it "accepts any value that is castable to integer" do
|
|
17
40
|
expect { dummy.number = '42' }.to_not raise_error(ArgumentError)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bikepoa-tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|