santas_little_helper 0.0.10 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/santas_little_helper.rb +156 -71
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3a78a7ba1fc653765b2e4885f6d1ec0f0354ca2
4
- data.tar.gz: 19424e3d6f5c21cc2ea035ed4ccbda7db6a59737
3
+ metadata.gz: e5e3c2d83766c76407d80f95c14a3b7c216ce412
4
+ data.tar.gz: fff37c2f2aa5859d5a605788fa27762665969215
5
5
  SHA512:
6
- metadata.gz: f0f68e62783c94d6339f1a368323ad135cebd247ad07a7f2b72b18fa46ab3b8f82912abad10cbdb6e504c2965d0b55801e6d1eb15afdbef413981665e912122d
7
- data.tar.gz: 83c0858fe74816861090774a1d9d3a73035c3226aa15db3345d91c35de93dffac2b273ce324a87da957b92d59b88c13f4706f28b3a0ee26156a13c44dc03d371
6
+ metadata.gz: 456c5508c334efddce6e879c4ba5bd7315192b6850ec54c1746af24b2e315475068049b54c8e717a2b7371485ae765910cb2e35d872cb6b8648609560baf42cc
7
+ data.tar.gz: 0e18b2d96daefac5a37bf9306183dc00d5b360724317eeece16df2e9429339d01959e2f4a6c66e1189353326ab7c37cd2d75f08c31b0ed0b2d6a00b6d1afdef2
@@ -9,20 +9,43 @@
9
9
  # Not really worried about maglev & rubinius & ironruby right now - as they are not really mutiplatform, not as widespread and I can't test for
10
10
  # them right now.
11
11
 
12
- # Works on Windows XP, 2003, 7 running Ruby 1.8.6 & 1.8.7 installed from RubyInstaller
13
- def windows?
14
- # Can't match for just 'win' cause it will match darwin as well.
15
- (/win32|mswin|mingw/).match(RUBY_PLATFORM) ? true : false
12
+
13
+ def ruby_platform
14
+ case RUBY_PLATFORM
15
+ when /win32|mswin|mingw/
16
+ # Works on Windows XP, 2003, 7, 8 running Ruby 1.8.6 & 1.8.7, 1.9.2, 1.9.3 & 2.0.0 installed from RubyInstaller
17
+ # Can't match for just 'win' cause it will match darwin as well.
18
+ 'windows'
19
+ when /linux/
20
+ # Works on Debian Sarge, Lenny & Wheezy and Ubuntu 9.10 running REE 1.8.7 & MRI 2.0.0 32-bit & 64-bit, don't have anything else to test on.
21
+ 'linux'
22
+ when /darwin/
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
+ '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
+ else
31
+ nil
32
+ end
16
33
  end
17
34
 
18
- # Works on Debian Sarge & Lenny and Ubuntu 9.10 running REE 1.8.7, don't have anything else to test on.
19
- def linux?
20
- (/linux/).match(RUBY_PLATFORM) ? true : false
35
+ def ruby_platform?(os='')
36
+ # Takes a string or a method like so platform?(:windows)
37
+ os.to_s.match(ruby_platform) ? true : false
21
38
  end
22
39
 
23
- # Works on my MacBook Pro OS 10.6 running Ruby 1.8.7 and rvm version of 1.9.1 , don't have anything else to test on,
40
+ # These are just aliases for convinience, I really doubt somebody would use them System Wide on an object for any other purpose.
41
+ def windows?
42
+ ruby_platform?(:windows)
43
+ end
44
+ def linux?
45
+ ruby_platform?(:linux)
46
+ end
24
47
  def mac?
25
- (/darwin/).match(RUBY_PLATFORM) ? true : false
48
+ ruby_platform?(:mac)
26
49
  end
27
50
 
28
51
 
@@ -30,78 +53,140 @@ end
30
53
  # I test and deploy some of the project on jruby - this makes it easier to customize my gemfiles.
31
54
  # Works for ruby 1.8.7 & 1.9.3 & 1.9.2 on windows( 7 & xp) & linux ( debian Lenny) using rubyinstaller for windows and using mri ruby buillt from source for linux
32
55
  # Works for jruby 1.7.0.rc1 and jruby 1.6.3 on windows (7 & xp)
56
+ # 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
+ # In the future I may start using RUBY_ENGINE
58
+ def ruby_implementation
59
+ ruby_platform
60
+ end
61
+ def ruby_implementation?(written_in='')
62
+ ruby_platform?(written_in)
63
+ end
33
64
  def jruby?
34
- (/java/).match(RUBY_PLATFORM) ? true : false
65
+ ruby_implementation?(:jruby)
35
66
  end
36
-
37
67
  def mri?
38
- (/i386|x86_64|x86/).match(RUBY_PLATFORM) ? true : false
68
+ ruby_implementation?(:mri)
39
69
  end
40
70
 
41
71
 
42
72
  # In case ruby ever reaches version 19 :-) or some 2.19 :-) only matching 1.9 at the begining of the line
43
- def version_1_9?
44
- (/^1.9./).match(RUBY_VERSION) ? true : false
73
+ # Returns an integer for easy version comparison 200 > 187 ( Version two is newer :-) )
74
+ # if ruby_version > 187 , install new version of the gem.
75
+ def ruby_version
76
+ RUBY_VERSION.gsub(/[^0-9]/,'').to_i
45
77
  end
46
-
47
- def version_1_8?
48
- (/^1.8./).match(RUBY_VERSION) ? true : false
78
+ def ruby_version?(version_to_check)
79
+ # Be careful - this will only match up to minor release. It will not match patch versions.
80
+ # You can ask it things in the following formats ruby_version?(1), ruby_version?(1.8), ruby_version?('200')
81
+ version_to_check = version_to_check.to_s.gsub(/[^0-9]/,'')
82
+ RUBY_VERSION.gsub(/[^0-9]/,'')[0..(version_to_check.size-1)] == version_to_check[0..(version_to_check.size-1)]
49
83
  end
50
84
 
51
85
 
52
- # When something is True / False and I can to_s it, why can't I to_i it?
53
- # There is actually a good theoretical reason, but in real world it really helps if you can output true or false 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.
54
- # For an alternative solution check out http://www.ruby-forum.com/topic/206789#new
55
-
56
- class TrueClass
57
- # Rails conventions for boolean / tinyint
58
- def to_i
59
- 1
60
- end
61
-
62
- # Humanize. to_s returns "true"
63
- def to_h
64
- "yes"
65
- end
66
-
67
- # Really I need to spell it out to you?
68
- def to_teenager
69
- "Yeah, yeah. Here you go. Did you get what you came for? Now disappear."
70
- end
71
- end
72
- class FalseClass
73
- # Rails conventions for boolean / tinyint
74
- def to_i
75
- 0
76
- end
77
- # Humanize. to_s returns "false".
78
- def to_h
79
- "no"
80
- end
81
- # Little obnoxious teenager.
82
- def to_teenager
83
- "Can't you leave me alone? I don't have anything!"
84
- end
85
- end
86
- class NilClass
87
- # Since in if/else nil is interpreted as false, return same as false.
88
- def to_i
89
- 0
90
- end
91
-
92
- # Humanize. to_s returns "" as well, this is really to be consistent with other classes.
93
- def to_h
94
- ""
95
- end
96
-
97
- # A very rude teenager nihilist.
98
- def to_teenager
99
- "Zip! Nada! Babkis! Nothing to see here! Get out of my room!"
100
- end
101
- end
102
- class String
103
- # See http://stackoverflow.com/questions/8119970/string-true-and-false-to-boolean
104
- def to_boolean
105
- !!(self =~ /^(true|t|yes|y|1)$/i)
86
+ if ruby_version >= 200
87
+ module SantasLittleHelper
88
+
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
+
97
+
98
+ refine TrueClass do
99
+ # Rails conventions for boolean / tinyint
100
+ def to_i
101
+ 1
102
+ end
103
+
104
+ # Humanize. to_s returns "true"
105
+ def to_human
106
+ "yes"
107
+ end
108
+
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
190
+ end
106
191
  end
107
192
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: santas_little_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gorbikoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-23 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  This is a collection of useful little snippets that I used through out various projects. If there is something you would like to add either check it out and modify it the way you want or let me know and I might add it here.
@@ -21,7 +21,8 @@ files:
21
21
  homepage: https://github.com/konung/santas_little_helper
22
22
  licenses: []
23
23
  metadata: {}
24
- post_install_message:
24
+ post_install_message: "\n\n\n\n !!!!!!!\n\n This version of Santas Little Helper
25
+ introduces some major changes. Read source, method_names changed! \n\n\n"
25
26
  rdoc_options: []
26
27
  require_paths:
27
28
  - lib
@@ -43,4 +44,4 @@ specification_version: 4
43
44
  summary: It's dumb just like the famous dog, but it may surprise you. It modifies
44
45
  core classes, use at your own risk!
45
46
  test_files: []
46
- has_rdoc:
47
+ has_rdoc: false