santas_little_helper 3.0.3 → 4.0.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.
- checksums.yaml +4 -4
- data/lib/santas_little_helper.rb +106 -106
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b42fda0df3477ce29da3770b77c29bace8f08cc7
|
4
|
+
data.tar.gz: 2ffd4599da8255b8c0a374fa6cf2b0cc0acdad76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0dfb99543cfc551304580215db52818d96a33d1e7ef4ecad1b49a70d4f7bf15e0666cc4e3b7a011f0959c9a64b23f90747ace0425b589abd19358756fc6a864
|
7
|
+
data.tar.gz: 06a31feac4ef5aa29beac399f8eae5914b00144ec815693cb06bd0e79b38851d9162945a7301ec92258eb5081c8016df5113d0a62f1c9bb5719aa4ff966b9959
|
data/lib/santas_little_helper.rb
CHANGED
@@ -22,11 +22,6 @@ def ruby_platform
|
|
22
22
|
when /darwin/
|
23
23
|
# Works on my MacBook Pro OS 10.6 running Ruby 1.8.7 and .rbenv version of 1.9.3 & 2.0.0 , don't have anything else to test on,
|
24
24
|
'mac'
|
25
|
-
when /java/
|
26
|
-
'jruby'
|
27
|
-
when /i386|x86_64|x86/
|
28
|
-
# I'm actually not sure what rubinius or maglev or other implementions would return. I don't rubies, other than mri or jruby.
|
29
|
-
'mri'
|
30
25
|
else
|
31
26
|
nil
|
32
27
|
end
|
@@ -56,10 +51,18 @@ end
|
|
56
51
|
# At this point it's essentially just an alias fro platform & platform?, since it queries RUBY_PLATFORM, but this may change in the future
|
57
52
|
# In the future I may start using RUBY_ENGINE
|
58
53
|
def ruby_implementation
|
59
|
-
|
54
|
+
case RUBY_ENGINE
|
55
|
+
when /java/
|
56
|
+
'jruby'
|
57
|
+
when /ruby/
|
58
|
+
# I'm actually not sure what rubinius or maglev or other implementions would return. I don't use rubies, other than mri or jruby.
|
59
|
+
'mri'
|
60
|
+
else
|
61
|
+
nil
|
62
|
+
end
|
60
63
|
end
|
61
64
|
def ruby_implementation?(written_in='')
|
62
|
-
|
65
|
+
written_in.to_s.match(ruby_implementation) ? true : false
|
63
66
|
end
|
64
67
|
def jruby?
|
65
68
|
ruby_implementation?(:jruby)
|
@@ -83,110 +86,107 @@ def ruby_version?(version_to_check)
|
|
83
86
|
end
|
84
87
|
|
85
88
|
|
86
|
-
if ruby_version >= 200
|
87
|
-
module SantasLittleHelper
|
88
89
|
|
89
|
-
# When something is True / False and I can to_s it, why can't I to_i it?
|
90
|
-
# There is actually a good theoretical reason, but in real world it really helps if you can output true or false
|
91
|
-
# as an int when you are sending soap request to a client, whose api requires it as 1 or 0, or humanize to "yes" & "no" form
|
92
|
-
# since users apperently are not good at understaning what true or false means in some context.
|
93
|
-
# Also why this can be done at a presentation level, when you are trying to create a meta method to handle complex objects
|
94
|
-
# this is much more convinient and readable.
|
95
|
-
# For an alternative solution check out http://www.ruby-forum.com/topic/206789#new
|
96
90
|
|
91
|
+
# When something is True / False and I can to_s it, why can't I to_i it?
|
92
|
+
# There is actually a good theoretical reason, but in real world it really helps if you can output true or false
|
93
|
+
# as an int when you are sending soap request to a client, whose api requires it as 1 or 0, or humanize to "yes" & "no" form
|
94
|
+
# since users apperently are not good at understaning what true or false means in some context.
|
95
|
+
# Also why this can be done at a presentation level, when you are trying to create a meta method to handle complex objects
|
96
|
+
# this is much more convinient and readable.
|
97
|
+
# For an alternative solution check out http://www.ruby-forum.com/topic/206789#new
|
97
98
|
|
98
|
-
refine TrueClass do
|
99
|
-
# Rails conventions for boolean / tinyint
|
100
|
-
def to_i
|
101
|
-
1
|
102
|
-
end
|
103
99
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
class TrueClass
|
101
|
+
# Rails conventions for boolean / tinyint
|
102
|
+
def to_i
|
103
|
+
1
|
104
|
+
end
|
108
105
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
def to_teenager
|
172
|
-
"I'm not good with whole numbers! I don't like math! Take your #{self.to_human} and go bother someone else!"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
refine Numeric do
|
176
|
-
# Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
|
177
|
-
def to_boolean
|
178
|
-
if self <= 0
|
179
|
-
false
|
180
|
-
else
|
181
|
-
true
|
182
|
-
end
|
183
|
-
end
|
184
|
-
def to_human
|
185
|
-
self.to_s
|
186
|
-
end
|
187
|
-
def to_teenager
|
188
|
-
"I told you I'm not good with whole numbers, what makes you think, I'm good with with fractions like this? #{self.to_human}"
|
189
|
-
end
|
106
|
+
# Humanize. to_s returns "true"
|
107
|
+
def to_human
|
108
|
+
"yes"
|
109
|
+
end
|
110
|
+
|
111
|
+
# Really?! Do I need to spell it out to you?
|
112
|
+
def to_teenager
|
113
|
+
"Yeah, yeah. Here you go. Did you get what you came for? Now disappear."
|
114
|
+
end
|
115
|
+
end
|
116
|
+
class FalseClass
|
117
|
+
# Rails conventions for boolean / tinyint
|
118
|
+
def to_i
|
119
|
+
0
|
120
|
+
end
|
121
|
+
|
122
|
+
# Humanize. to_s returns "false".
|
123
|
+
def to_human
|
124
|
+
"no"
|
125
|
+
end
|
126
|
+
|
127
|
+
# Little obnoxious teenager.
|
128
|
+
def to_teenager
|
129
|
+
"No means no!!! Can't you leave me alone?"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
class NilClass
|
133
|
+
# Since in if/else nil is interpreted as false, return same as false.
|
134
|
+
def to_i
|
135
|
+
0
|
136
|
+
end
|
137
|
+
|
138
|
+
# Humanize. to_s returns "" as well, this is really to be consistent with other classes.
|
139
|
+
def to_human
|
140
|
+
""
|
141
|
+
end
|
142
|
+
|
143
|
+
# A very rude teenager nihilist.
|
144
|
+
def to_teenager
|
145
|
+
"Zip! Nada! Babkis! Nothing to see here! Get out of my room!"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
class String
|
149
|
+
# See http://stackoverflow.com/questions/8119970/string-true-and-false-to-boolean
|
150
|
+
# In this context empty string is nil which is the same as false
|
151
|
+
def to_boolean
|
152
|
+
!!(self =~ /^(true|t|yes|y|1)$/i)
|
153
|
+
end
|
154
|
+
def to_human
|
155
|
+
self.to_s
|
156
|
+
end
|
157
|
+
def to_teenager
|
158
|
+
"What did you say to me? What? #{self.to_human}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
class Fixnum
|
162
|
+
# Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
|
163
|
+
def to_boolean
|
164
|
+
if self <= 0
|
165
|
+
false
|
166
|
+
else
|
167
|
+
true
|
190
168
|
end
|
191
169
|
end
|
170
|
+
def to_human
|
171
|
+
self.to_s
|
172
|
+
end
|
173
|
+
def to_teenager
|
174
|
+
"I'm not good with whole numbers! I don't like math! Take your #{self.to_human} and go bother someone else!"
|
175
|
+
end
|
192
176
|
end
|
177
|
+
class Float
|
178
|
+
# Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
|
179
|
+
def to_boolean
|
180
|
+
if self <= 0
|
181
|
+
false
|
182
|
+
else
|
183
|
+
true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
def to_human
|
187
|
+
self.to_s
|
188
|
+
end
|
189
|
+
def to_teenager
|
190
|
+
"I told you I'm not good with whole numbers, what makes you think, I'm good with with fractions like this? #{self.to_human}"
|
191
|
+
end
|
192
|
+
end
|