core_extend 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e9d56ced4bc7c5adbdb561052adb0ce9de631a3
4
- data.tar.gz: f19b929050ede5c05232e0ab36ba608cd71f3122
3
+ metadata.gz: bdae9b5882a313ffe12d0b2f3e485213e0ed2d60
4
+ data.tar.gz: c3c9a6434939aa9373d6f0ddc1b3b8674fc0e4f8
5
5
  SHA512:
6
- metadata.gz: 1db03188c6476bd71bbdc82f6b84aa47d88486fe7c94e15042b6d9325c3c299388926661d8a18592ef5bc92c4a60524185e57af6b047ddea7b6f75bc359c4766
7
- data.tar.gz: b72c61facca1c5c34d40f0326f96f8dd7e0d05c1264131c652009c5012f87b3e20113bdece3a0b6cb926bc6a2b1c08cfcee2b48d5e89e19ab3ad8f23d5a7ef04
6
+ metadata.gz: 1f6bce0b5738aa878081d0748b266ecb7070d2925227439dc8bad081d1bf96577f39875f5d36444c83d35223a8a875c2f1cb32a56017023bcc9b3db245129a69
7
+ data.tar.gz: eb5cd5433c3c358be10fc93fb2b414045b743a270a3a42ab0a7698322d9c3229e4ff56d396eeac917ffbe59ab8c66d5de9b15510bceb8620b58785537cfa8937
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- core_extend (0.1.4)
4
+ core_extend (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- it 'every' do
29
- (1..20).to_a.every(3) { |a, b, c|
30
- p "#{a},#{b},#{c}"
31
- }
32
- end
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,"
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
- 3.2268.decimal_point(2)
46
+ 3.2268.decimal_point(2)
47
47
  #=>3.23
48
48
  ```
49
49
  ###to_money
50
50
  ```ruby
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"
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
- str = Random.rand_str(32)
65
- p str
66
- #=>"tdb1hruwxd8p0z5qtdl7pvhva5uxbru9"
64
+ str = Random.rand_str(32)
65
+ p str
66
+ #=>"tdb1hruwxd8p0z5qtdl7pvhva5uxbru9"
67
67
  ```
68
68
 
69
69
 
@@ -0,0 +1,3 @@
1
+ class String
2
+
3
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module CoreExtend
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.7'
3
3
  end
data/lib/core_extend.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'core_extend/version'
2
+ require 'erb'
2
3
  require 'core_extend/float_module'
3
4
 
4
5
  Dir.glob("#{File.dirname(__FILE__)}/core_extend/*.rb") { |f| require f }
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.5
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-07-27 00:00:00.000000000 Z
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