wnm_support 0.0.2
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/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/changelog.md +6 -0
- data/lib/wnm_support/core_ext/class_exists.rb +6 -0
- data/lib/wnm_support/core_ext/halved.rb +8 -0
- data/lib/wnm_support/core_ext/is_integer.rb +5 -0
- data/lib/wnm_support/core_ext/map_to_hash.rb +7 -0
- data/lib/wnm_support/core_ext/max_words.rb +10 -0
- data/lib/wnm_support/core_ext/to_array.rb +11 -0
- data/lib/wnm_support/core_ext/to_boolean.rb +31 -0
- data/lib/wnm_support/core_ext/to_integer.rb +15 -0
- data/lib/wnm_support/core_ext/unicode.rb +15 -0
- data/lib/wnm_support/version.rb +3 -0
- data/lib/wnm_support.rb +10 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/wnm_support/core_ext/array_spec.rb +20 -0
- data/spec/wnm_support/core_ext/class_exists_spec.rb +15 -0
- data/spec/wnm_support/core_ext/false_class_spec.rb +17 -0
- data/spec/wnm_support/core_ext/integer_spec.rb +25 -0
- data/spec/wnm_support/core_ext/nil_class_spec.rb +10 -0
- data/spec/wnm_support/core_ext/string_spec.rb +34 -0
- data/spec/wnm_support/core_ext/true_class_spec.rb +17 -0
- data/wnm_support.gemspec +23 -0
- metadata +128 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Miroslav Hettes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# WnmSupport
|
2
|
+
|
3
|
+
add some useful methods to core class for rails project
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "wnm_support", :git => "git@bitbucket.org:mirrec/wnm_support.git"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Core extentions
|
18
|
+
|
19
|
+
|
20
|
+
1.to_b # => true
|
21
|
+
1.to_b # => false
|
22
|
+
|
23
|
+
true.to_i # => 1
|
24
|
+
false.to_i # => 0
|
25
|
+
|
26
|
+
"123".is_integer? # => true
|
27
|
+
"123ad".is_integer? # => false
|
28
|
+
|
29
|
+
"one more something".max_words(2, "..") # => "one more.."
|
30
|
+
|
31
|
+
"some".to_a # => ["some"]
|
32
|
+
1.to_a # => [1]
|
33
|
+
|
34
|
+
[ ["k1", "v1"], ["k2", "v2"] ].map_to_hash{|item| {item.first => item.last} } # => {"k1" => "v1", "k2" => "b2"}
|
35
|
+
|
36
|
+
[1,2,3,4].halved # => [ [1, 2], [3, 4] ]
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/changelog.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Integer
|
2
|
+
def to_b
|
3
|
+
!self.zero?
|
4
|
+
end
|
5
|
+
|
6
|
+
alias_method :to_bool, :to_b
|
7
|
+
end
|
8
|
+
|
9
|
+
class TrueClass
|
10
|
+
def to_b
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :to_bool, :to_b
|
15
|
+
end
|
16
|
+
|
17
|
+
class FalseClass
|
18
|
+
def to_b
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :to_bool, :to_b
|
23
|
+
end
|
24
|
+
|
25
|
+
class NilClass
|
26
|
+
def to_b
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :to_bool, :to_b
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class String
|
2
|
+
#def unicode_upcase
|
3
|
+
# UnicodeUtils.upcase(self)
|
4
|
+
#end
|
5
|
+
#
|
6
|
+
#def unicode_downcase
|
7
|
+
# UnicodeUtils.downcase(self)
|
8
|
+
#end
|
9
|
+
#
|
10
|
+
#def unicode_titleize
|
11
|
+
# UnicodeUtils.titleize(self)
|
12
|
+
#end
|
13
|
+
|
14
|
+
#alias_method :unicode_titlecase, :unicode_titleize
|
15
|
+
end
|
data/lib/wnm_support.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "wnm_support/version"
|
2
|
+
|
3
|
+
require "wnm_support/core_ext/class_exists"
|
4
|
+
require "wnm_support/core_ext/to_boolean"
|
5
|
+
require "wnm_support/core_ext/to_integer"
|
6
|
+
require "wnm_support/core_ext/to_array"
|
7
|
+
require "wnm_support/core_ext/is_integer"
|
8
|
+
require "wnm_support/core_ext/max_words"
|
9
|
+
require "wnm_support/core_ext/map_to_hash"
|
10
|
+
require "wnm_support/core_ext/halved"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe "map_to_hash" do
|
5
|
+
it "should return an hash from given array" do
|
6
|
+
array = [
|
7
|
+
[1, false, "string"],
|
8
|
+
[2, true, nil]
|
9
|
+
]
|
10
|
+
hash = array.map_to_hash{|item| {item.first => item.last} }
|
11
|
+
hash.should eq({1 => "string", 2 => nil})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "halved" do
|
16
|
+
it "should split array in two array in half" do
|
17
|
+
[1,2,3,4].halved.should eq [ [1, 2], [3, 4] ]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "class_exists?" do
|
4
|
+
it "should return true if given class exists" do
|
5
|
+
class MyTest
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
class_exists?("MyTest").should eq true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return false if given class does not exists" do
|
13
|
+
class_exists?("NoExist").should eq false
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FalseClass do
|
4
|
+
describe "to_bool" do
|
5
|
+
it "should return false" do
|
6
|
+
false.to_bool.should eq false
|
7
|
+
false.to_b.should eq false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "to_integer" do
|
12
|
+
it "should return 0" do
|
13
|
+
false.to_integer.should eq 0
|
14
|
+
false.to_i.should eq 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
describe "to_bool" do
|
5
|
+
it "should return false if integer is zero" do
|
6
|
+
0.to_bool.should eq false
|
7
|
+
0.to_b.should eq false
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return true if integer is not zero" do
|
11
|
+
1.to_bool.should eq true
|
12
|
+
1.to_b.should eq true
|
13
|
+
|
14
|
+
-1.to_bool.should eq true
|
15
|
+
-1.to_b.should eq true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "to_a" do
|
20
|
+
it "should wrap integer in array" do
|
21
|
+
1.to_a.should eq [1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "to_a" do
|
5
|
+
it "should wrap string in an array" do
|
6
|
+
"string".to_a.should eq ["string"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "is_integer?" do
|
11
|
+
it "should return true if string is a integer in string" do
|
12
|
+
"123".is_integer?.should eq true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return false if string has other chara" do
|
16
|
+
"123a".is_integer?.should eq false
|
17
|
+
"12.3".is_integer?.should eq false
|
18
|
+
"".is_integer?.should eq false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "max_words" do
|
23
|
+
let(:sentence) { "Hello I am a boy." }
|
24
|
+
|
25
|
+
it "should display hole sentence if there is less or equal number of words" do
|
26
|
+
sentence.max_words(10).should eq sentence
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should cut sentence to given number of words and add ending" do
|
30
|
+
sentence.max_words(2).should eq "Hello I..."
|
31
|
+
sentence.max_words(2, ".").should eq "Hello I."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TrueClass do
|
4
|
+
describe "to_bool" do
|
5
|
+
it "should return true" do
|
6
|
+
true.to_bool.should eq true
|
7
|
+
true.to_b.should eq true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "to_integer" do
|
12
|
+
it "should return 1" do
|
13
|
+
true.to_integer.should eq 1
|
14
|
+
true.to_i.should eq 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/wnm_support.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wnm_support/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "wnm_support"
|
8
|
+
gem.version = WnmSupport::VERSION
|
9
|
+
gem.authors = ["Miroslav Hettes"]
|
10
|
+
gem.email = ["mirrec@gmail.com"]
|
11
|
+
gem.description = %q{Extend core methods in Rails}
|
12
|
+
gem.summary = %q{Extend core method in Rails}
|
13
|
+
gem.homepage = "https://bitbucket.org/mirrec/wnm_support"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "activesupport"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wnm_support
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Miroslav Hettes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Extend core methods in Rails
|
63
|
+
email:
|
64
|
+
- mirrec@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- changelog.md
|
76
|
+
- lib/wnm_support.rb
|
77
|
+
- lib/wnm_support/core_ext/class_exists.rb
|
78
|
+
- lib/wnm_support/core_ext/halved.rb
|
79
|
+
- lib/wnm_support/core_ext/is_integer.rb
|
80
|
+
- lib/wnm_support/core_ext/map_to_hash.rb
|
81
|
+
- lib/wnm_support/core_ext/max_words.rb
|
82
|
+
- lib/wnm_support/core_ext/to_array.rb
|
83
|
+
- lib/wnm_support/core_ext/to_boolean.rb
|
84
|
+
- lib/wnm_support/core_ext/to_integer.rb
|
85
|
+
- lib/wnm_support/core_ext/unicode.rb
|
86
|
+
- lib/wnm_support/version.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/wnm_support/core_ext/array_spec.rb
|
89
|
+
- spec/wnm_support/core_ext/class_exists_spec.rb
|
90
|
+
- spec/wnm_support/core_ext/false_class_spec.rb
|
91
|
+
- spec/wnm_support/core_ext/integer_spec.rb
|
92
|
+
- spec/wnm_support/core_ext/nil_class_spec.rb
|
93
|
+
- spec/wnm_support/core_ext/string_spec.rb
|
94
|
+
- spec/wnm_support/core_ext/true_class_spec.rb
|
95
|
+
- wnm_support.gemspec
|
96
|
+
homepage: https://bitbucket.org/mirrec/wnm_support
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.24
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Extend core method in Rails
|
120
|
+
test_files:
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/wnm_support/core_ext/array_spec.rb
|
123
|
+
- spec/wnm_support/core_ext/class_exists_spec.rb
|
124
|
+
- spec/wnm_support/core_ext/false_class_spec.rb
|
125
|
+
- spec/wnm_support/core_ext/integer_spec.rb
|
126
|
+
- spec/wnm_support/core_ext/nil_class_spec.rb
|
127
|
+
- spec/wnm_support/core_ext/string_spec.rb
|
128
|
+
- spec/wnm_support/core_ext/true_class_spec.rb
|