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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/santas_little_helper.rb +106 -106
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5e3c2d83766c76407d80f95c14a3b7c216ce412
4
- data.tar.gz: fff37c2f2aa5859d5a605788fa27762665969215
3
+ metadata.gz: b42fda0df3477ce29da3770b77c29bace8f08cc7
4
+ data.tar.gz: 2ffd4599da8255b8c0a374fa6cf2b0cc0acdad76
5
5
  SHA512:
6
- metadata.gz: 456c5508c334efddce6e879c4ba5bd7315192b6850ec54c1746af24b2e315475068049b54c8e717a2b7371485ae765910cb2e35d872cb6b8648609560baf42cc
7
- data.tar.gz: 0e18b2d96daefac5a37bf9306183dc00d5b360724317eeece16df2e9429339d01959e2f4a6c66e1189353326ab7c37cd2d75f08c31b0ed0b2d6a00b6d1afdef2
6
+ metadata.gz: a0dfb99543cfc551304580215db52818d96a33d1e7ef4ecad1b49a70d4f7bf15e0666cc4e3b7a011f0959c9a64b23f90747ace0425b589abd19358756fc6a864
7
+ data.tar.gz: 06a31feac4ef5aa29beac399f8eae5914b00144ec815693cb06bd0e79b38851d9162945a7301ec92258eb5081c8016df5113d0a62f1c9bb5719aa4ff966b9959
@@ -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
- ruby_platform
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
- ruby_platform?(written_in)
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
- # Humanize. to_s returns "true"
105
- def to_human
106
- "yes"
107
- end
100
+ class TrueClass
101
+ # Rails conventions for boolean / tinyint
102
+ def to_i
103
+ 1
104
+ end
108
105
 
109
- # Really?! Do I need to spell it out to you?
110
- def to_teenager
111
- "Yeah, yeah. Here you go. Did you get what you came for? Now disappear."
112
- end
113
- end
114
- refine FalseClass do
115
- # Rails conventions for boolean / tinyint
116
- def to_i
117
- 0
118
- end
119
-
120
- # Humanize. to_s returns "false".
121
- def to_human
122
- "no"
123
- end
124
-
125
- # Little obnoxious teenager.
126
- def to_teenager
127
- "No means no!!! Can't you leave me alone?"
128
- end
129
- end
130
- refine NilClass do
131
- # Since in if/else nil is interpreted as false, return same as false.
132
- def to_i
133
- 0
134
- end
135
-
136
- # Humanize. to_s returns "" as well, this is really to be consistent with other classes.
137
- def to_human
138
- ""
139
- end
140
-
141
- # A very rude teenager nihilist.
142
- def to_teenager
143
- "Zip! Nada! Babkis! Nothing to see here! Get out of my room!"
144
- end
145
- end
146
- refine String do
147
- # See http://stackoverflow.com/questions/8119970/string-true-and-false-to-boolean
148
- # In this context empty string is nil which is the same as false
149
- def to_boolean
150
- !!(self =~ /^(true|t|yes|y|1)$/i)
151
- end
152
- def to_human
153
- self.to_s
154
- end
155
- def to_teenager
156
- "What did you say to me? What? #{self.to_human}"
157
- end
158
- end
159
- refine Integer do
160
- # Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
161
- def to_boolean
162
- if self <= 0
163
- false
164
- else
165
- true
166
- end
167
- end
168
- def to_human
169
- self.to_s
170
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: santas_little_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gorbikoff