paranoid_starlight 1.0.0 → 1.1.0
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/lib/paranoid_starlight/version.rb +1 -1
- data/lib/paranoid_starlight.rb +34 -14
- data/specs/paranoid_starlight_spec.rb +9 -1
- metadata +2 -2
data/lib/paranoid_starlight.rb
CHANGED
@@ -112,24 +112,44 @@ module ParanoidStarlight
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def convert_telephone_number(inattr, outattr = '')
|
115
|
-
inattr
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
basic_converter(self, inattr, outattr) do |telephone|
|
116
|
+
::ParanoidStarlight::Converters.convert_telephone(
|
117
|
+
telephone,
|
118
|
+
TwitterCldr::Shared::PhoneCodes.code_for_territory(
|
119
|
+
FastGettext.locale.to_sym
|
120
|
+
)
|
121
|
+
) rescue nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def clean_text(inattr, outattr = '')
|
126
|
+
basic_converter(self, inattr, outattr) do |text|
|
127
|
+
text.to_s.strip.gsub(/\s{2,}/, ' ')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
def basic_converter(obj, inattr, outattr, &code)
|
133
|
+
unless obj.respond_to? inattr.to_sym
|
134
|
+
raise("Attribute #{inattr} does not exist.")
|
135
|
+
end
|
136
|
+
|
119
137
|
outattr = inattr if outattr == ''
|
120
|
-
|
138
|
+
|
139
|
+
unless obj.respond_to? outattr.to_sym
|
140
|
+
raise("Attribute #{outattr} does not exist.")
|
141
|
+
end
|
142
|
+
|
121
143
|
setter = "#{outattr}=".to_sym
|
144
|
+
unless obj.respond_to? setter
|
145
|
+
raise("Setter #{setter} does not exist.")
|
146
|
+
end
|
122
147
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
) rescue nil
|
148
|
+
to_convert = obj.send(inattr.to_sym)
|
149
|
+
unless to_convert.nil?
|
150
|
+
obj.send(setter, code.call(to_convert))
|
151
|
+
end
|
128
152
|
|
129
|
-
self.send(setter, num) unless num.nil?
|
130
|
-
else
|
131
|
-
raise("Attribute #{inattr} does not exist.")
|
132
|
-
end
|
133
153
|
end
|
134
154
|
|
135
155
|
end # end converters
|
@@ -7,6 +7,7 @@ require 'rspec'
|
|
7
7
|
class Fangirl
|
8
8
|
include ::ParanoidStarlight::Converters
|
9
9
|
attr_accessor :telephone_from_form, :telephone
|
10
|
+
attr_accessor :text
|
10
11
|
end
|
11
12
|
|
12
13
|
describe ParanoidStarlight::Converters do
|
@@ -55,7 +56,7 @@ describe ParanoidStarlight::Converters do
|
|
55
56
|
|
56
57
|
end
|
57
58
|
|
58
|
-
describe 'convert_telephone_number' do
|
59
|
+
describe 'convert_telephone_number (for attributes)' do
|
59
60
|
before :each do
|
60
61
|
FastGettext.locale = 'sk'
|
61
62
|
@test = Fangirl.new
|
@@ -75,7 +76,14 @@ describe ParanoidStarlight::Converters do
|
|
75
76
|
@test.telephone_from_form.should == '421123456789'
|
76
77
|
end
|
77
78
|
end
|
79
|
+
end
|
78
80
|
|
81
|
+
describe 'clean_text (for attributes)' do
|
82
|
+
before { @test = Fangirl.new; @test.text = " Some \ttext. \t" }
|
83
|
+
it 'should clean text of unneccessary characters' do
|
84
|
+
@test.clean_text(:text)
|
85
|
+
@test.text.should == "Some text."
|
86
|
+
end
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoid_starlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
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: 2012-12-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|