core_extend 0.1.5 → 0.1.7
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/Gemfile.lock +1 -1
- data/README.md +23 -23
- data/lib/core_extend/String.rb +3 -0
- data/lib/core_extend/float_module.rb +27 -0
- data/lib/core_extend/version.rb +1 -1
- data/lib/core_extend.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdae9b5882a313ffe12d0b2f3e485213e0ed2d60
|
4
|
+
data.tar.gz: c3c9a6434939aa9373d6f0ddc1b3b8674fc0e4f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6bce0b5738aa878081d0748b266ecb7070d2925227439dc8bad081d1bf96577f39875f5d36444c83d35223a8a875c2f1cb32a56017023bcc9b3db245129a69
|
7
|
+
data.tar.gz: eb5cd5433c3c358be10fc93fb2b414045b743a270a3a42ab0a7698322d9c3229e4ff56d396eeac917ffbe59ab8c66d5de9b15510bceb8620b58785537cfa8937
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,9 @@ gem主要包括数组的遍历、浮点数的小数点精度的确定、金钱
|
|
5
5
|
## Installation
|
6
6
|
Add this line to `config/application.rb`
|
7
7
|
|
8
|
+
```ruby
|
8
9
|
require 'core_extend'
|
10
|
+
```
|
9
11
|
|
10
12
|
Add this line to your application's Gemfile:
|
11
13
|
|
@@ -25,45 +27,43 @@ Or install it yourself as:
|
|
25
27
|
|
26
28
|
### every
|
27
29
|
```ruby
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#=>"16,17,18"
|
39
|
-
#=>"19,20,"
|
30
|
+
(1..20).to_a.every(3) { |a, b, c|
|
31
|
+
p "#{a},#{b},#{c}"
|
32
|
+
}
|
33
|
+
#=>"1,2,3"
|
34
|
+
#=>"4,5,6"
|
35
|
+
#=>"7,8,9"
|
36
|
+
#=>"10,11,12"
|
37
|
+
#=>"13,14,15"
|
38
|
+
#=>"16,17,18"
|
39
|
+
#=>"19,20,"
|
40
40
|
```
|
41
41
|
|
42
42
|
## Float
|
43
43
|
|
44
44
|
###decimal_point
|
45
45
|
```ruby
|
46
|
-
|
46
|
+
3.2268.decimal_point(2)
|
47
47
|
#=>3.23
|
48
48
|
```
|
49
49
|
###to_money
|
50
50
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
123456789.456.to_money #=>"123,456,789.46"
|
52
|
+
32005487.45.to_money('text') #=>"3200.55万"
|
53
|
+
2332005487.45.to_money('text',4) #=>"23.3201亿"
|
54
|
+
2332005487.45.to_money('text',0) #=>"23亿"
|
55
|
+
2332005487.45.to_money('num',2) #=>"2,332,005,487.45"
|
56
|
+
2332005487.45.to_money('num',0) #=>"2,332,005,487"
|
57
|
+
1.to_money #=>"1.0"
|
58
58
|
```
|
59
59
|
|
60
60
|
## Random
|
61
61
|
|
62
62
|
###rand_str
|
63
63
|
```ruby
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
str = Random.rand_str(32)
|
65
|
+
p str
|
66
|
+
#=>"tdb1hruwxd8p0z5qtdl7pvhva5uxbru9"
|
67
67
|
```
|
68
68
|
|
69
69
|
|
@@ -38,5 +38,32 @@ module CoreExtend
|
|
38
38
|
end
|
39
39
|
return_value.call
|
40
40
|
end
|
41
|
+
|
42
|
+
def to_size(point=2)
|
43
|
+
str = decimal_point(point).to_s
|
44
|
+
int_str = str.split('.')[0]
|
45
|
+
point_str = str.split('.')[1]
|
46
|
+
|
47
|
+
return_value = ->() {
|
48
|
+
return "#{int_str}.#{point_str} bytes" if point>0
|
49
|
+
int_str
|
50
|
+
}
|
51
|
+
|
52
|
+
return return_value.call if int_str.to_i<1000
|
53
|
+
|
54
|
+
return "#{(int_str.to_i/1000.0).decimal_point(point)} KB" if int_str.to_i<1000*1000
|
55
|
+
|
56
|
+
return "#{(int_str.to_i/(1000*1000.0)).decimal_point(point)} MB" if int_str.to_i<(1000*1000*1000)
|
57
|
+
|
58
|
+
|
59
|
+
return return_value.call if int_str.length<3
|
60
|
+
index = -4
|
61
|
+
while index.abs < int_str.length+1
|
62
|
+
int_str.insert(index, ',')
|
63
|
+
index -=4
|
64
|
+
end
|
65
|
+
return_value.call
|
66
|
+
end
|
67
|
+
|
41
68
|
end
|
42
69
|
end
|
data/lib/core_extend/version.rb
CHANGED
data/lib/core_extend.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core_extend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saxer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- bin/setup
|
57
57
|
- core_extend.gemspec
|
58
58
|
- lib/core_extend.rb
|
59
|
+
- lib/core_extend/String.rb
|
59
60
|
- lib/core_extend/array.rb
|
60
61
|
- lib/core_extend/big_decimal.rb
|
61
62
|
- lib/core_extend/float.rb
|