digit_delim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e50f4a154d5c40562dfebe807077312afc745822
4
+ data.tar.gz: 9bf8033451bba472ca8b84d282ab070348e7feae
5
+ SHA512:
6
+ metadata.gz: 6683d34ae966505dc8b27d786e6beb54ad9a637ea4c8e9e39fdecd0789679f24c0a7938d97521c398a2fc798f9dc9b1ea54d06db5a48aaa7145ac6f294e9cae4
7
+ data.tar.gz: 329f504f02f0683473a5e08e073f2e22bf2305a45a677685909a48de91fb3eec2c337ebf71436ea8325cd55f4e78dc5ef3215af3a235036fa4f340263c0012b4
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.3.5"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "simplecov-rcov", ">= 0"
14
+ end
@@ -0,0 +1,79 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.10)
12
+ builder (3.2.2)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ git (1.2.5)
16
+ github_api (0.10.1)
17
+ addressable
18
+ faraday (~> 0.8.1)
19
+ hashie (>= 1.2)
20
+ multi_json (~> 1.4)
21
+ nokogiri (~> 1.5.2)
22
+ oauth2
23
+ hashie (2.0.5)
24
+ highline (1.6.19)
25
+ httpauth (0.2.0)
26
+ i18n (0.6.4)
27
+ jeweler (1.8.6)
28
+ builder
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ github_api (= 0.10.1)
32
+ highline (>= 1.6.15)
33
+ nokogiri (= 1.5.10)
34
+ rake
35
+ rdoc
36
+ json (1.8.0)
37
+ jwt (0.1.8)
38
+ multi_json (>= 1.5)
39
+ minitest (4.7.5)
40
+ multi_json (1.7.7)
41
+ multi_xml (0.5.4)
42
+ multipart-post (1.2.0)
43
+ nokogiri (1.5.10)
44
+ oauth2 (0.9.2)
45
+ faraday (~> 0.8)
46
+ httpauth (~> 0.2)
47
+ jwt (~> 0.1.4)
48
+ multi_json (~> 1.0)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ rack (1.5.2)
52
+ rake (10.1.0)
53
+ rdoc (3.12.2)
54
+ json (~> 1.4)
55
+ shoulda (3.5.0)
56
+ shoulda-context (~> 1.0, >= 1.0.1)
57
+ shoulda-matchers (>= 1.4.1, < 3.0)
58
+ shoulda-context (1.1.4)
59
+ shoulda-matchers (2.2.0)
60
+ activesupport (>= 3.0.0)
61
+ simplecov (0.7.1)
62
+ multi_json (~> 1.0)
63
+ simplecov-html (~> 0.7.1)
64
+ simplecov-html (0.7.1)
65
+ simplecov-rcov (0.2.3)
66
+ simplecov (>= 0.4.1)
67
+ thread_safe (0.1.2)
68
+ atomic
69
+ tzinfo (0.3.37)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.3.5)
76
+ jeweler (~> 1.8.4)
77
+ rdoc (~> 3.12)
78
+ shoulda
79
+ simplecov-rcov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 YAMAMOTO, Masayuki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "digit_delim"
18
+ gem.homepage = "http://github.com/mephistobooks/digit_delim"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A little num-string formatter, converter.}
21
+ gem.description = %Q{methods of num-string formatter, converter which extends String class}
22
+ gem.email = "martin.route66.blues+github@gmail.com"
23
+ gem.authors = ["YAMAMOTO, Masayuki"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ #require 'rcov/rcovtask'
36
+ #Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ #end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "digit_delim #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
@@ -0,0 +1,24 @@
1
+ # digit_delim ReadMe
2
+
3
+ ## Description
4
+
5
+ provides the methods to separate a number with the delimiter for each 3 digits.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ [sudo] gem install digit_delim
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ See the test code.
16
+
17
+ ## Lisence
18
+ MIT Lisence.
19
+
20
+ ## About the Author
21
+ YAMAMOTO, Masayuki
22
+
23
+
24
+ # End.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "digit_delim"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["YAMAMOTO, Masayuki"]
12
+ s.date = "2013-07-30"
13
+ s.description = "methods of num-string formatter, converter which extends String class"
14
+ s.email = "martin.route66.blues+github@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "Rakefile",
24
+ "ReadMe.md",
25
+ "VERSION",
26
+ "digit_delim.gemspec",
27
+ "lib/digit_delim.rb",
28
+ "test/helper.rb",
29
+ "test/test_digit_delim.rb"
30
+ ]
31
+ s.homepage = "http://github.com/mephistobooks/digit_delim"
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "2.0.3"
35
+ s.summary = "A little num-string formatter, converter."
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 4
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
42
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
43
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.5"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
45
+ s.add_development_dependency(%q<simplecov-rcov>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
51
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
58
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,58 @@
1
+ #
2
+ # filename: digit_delim.rb
3
+ #
4
+ #
5
+
6
+ $NUM_DELIM_EACH = 3
7
+ $NUM_DELIM_CHAR = ','
8
+ $NUM_DELIM_ = '.'
9
+
10
+
11
+ class String
12
+
13
+ # :method: w_dm
14
+ # with delimiters: separate digit-string into each n-digits
15
+ # with delimiters.
16
+ # ==== Args
17
+ # n :: the number of digits length of separated string.
18
+ # ==== Return
19
+ # separated string.
20
+ def w_dm(n=3); self.gsub( /(\d+)?(\.\d*)?/ ) { \
21
+ s1="#{$1}".dup; s2="#{$2}".dup; \
22
+ s2="#{s2}00".slice(0,s2.size) if s2.size != 0
23
+ s1.reverse.gsub( /\d{#{n}}(?=\d)/ ){|r| r+","}.reverse+s2 }; end
24
+ alias to_f_old to_f
25
+
26
+ # :method: wo_dm
27
+ # without delimiters: remove the delimiters in digit-string.
28
+ # ==== Args
29
+ #
30
+ # ==== Return
31
+ # digit-string without the delimiters.
32
+ def wo_dm; self.gsub(/,/, ""); end
33
+
34
+ # :method: to_wof
35
+ # remove delimiters in digit-string and convert it to Float.
36
+ # ==== Args
37
+ #
38
+ # ==== Return
39
+ # number in Float
40
+ def to_wof; self.wo_dm.to_f_old; end
41
+
42
+ # :method: to_fu
43
+ # convert string to float concerning with unit.
44
+ # ==== Args
45
+ #
46
+ # ==== Return
47
+ # number in Float. if the original string has '%', the number is
48
+ # divided by 100.
49
+ def to_fu
50
+ ret = self.to_wof
51
+ if self =~ /%$/ then ret /= 100.0 else ret end
52
+ end
53
+
54
+ end
55
+
56
+
57
+
58
+ #### endof filename: digit_delim.rb
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'digit_delim'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,66 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # filename: test_digit_delim.rb
4
+ #
5
+ #
6
+ #require "rubygems"
7
+ #gem "test-unit"
8
+ #require "test/unit"
9
+ require "helper"
10
+ require 'test/unit'
11
+
12
+
13
+ require "digit_delim"
14
+
15
+
16
+ class TestDigitDelim < Test::Unit::TestCase
17
+
18
+ def test_w_dm_1
19
+ assert_equal( "123", "123".w_dm )
20
+ assert_equal( "23,456,789", "23456789".w_dm )
21
+ assert_equal( "23,456,789.0123", "23456789.0123".w_dm )
22
+ assert_equal( "23,456,789.0123", "23456789.0123".w_dm(3) )
23
+ assert_equal( "2345,6789.0123", "23456789.0123".w_dm(4) )
24
+ end
25
+
26
+ def test_w_dm_2
27
+ assert_equal( "0.0123", "0.0123".w_dm )
28
+ assert_equal( ".0123", ".0123".w_dm )
29
+ assert_equal( "0.0", "0.0".w_dm )
30
+ assert_equal( "0", "0".w_dm )
31
+ #assert_equal( "1,234.0", "1234.".w_dm )
32
+ assert_equal( "1,234.", "1234.".w_dm )
33
+ assert_equal( "1,234.01234", "1234.01234".w_dm )
34
+ assert_equal( "12,345,678.01234", "12345678.01234".w_dm )
35
+ end
36
+
37
+ def test_wo_dm
38
+ assert_equal( "100000", "100,000".wo_dm )
39
+ assert_equal( "100000.0123", "100,000.0123".wo_dm )
40
+ end
41
+
42
+ def test_to_wof
43
+ assert_equal( 100, "100,000".to_f )
44
+ assert_equal( 100000, "100,000".to_wof )
45
+
46
+ assert_equal( 100.0, "100,000".to_f )
47
+ end
48
+
49
+ def test_to_wof_stocks
50
+ assert_equal( 1, "1株".to_wof )
51
+ assert_equal( 1.05, "1.05株".to_wof )
52
+ end
53
+
54
+ def test_to_fu
55
+ assert_equal( 0.05, "5%".to_fu )
56
+ assert_equal( 1.05, "105%".to_fu )
57
+ assert_equal( 0.051, "5.1%".to_fu )
58
+ assert_equal( -0.051, "-5.1%".to_fu )
59
+
60
+ assert_equal( 5, "5".to_fu )
61
+ end
62
+
63
+ end
64
+
65
+
66
+ #### endof filename: test_digit_delim.rb
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digit_delim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - YAMAMOTO, Masayuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-rcov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: methods of num-string formatter, converter which extends String class
84
+ email: martin.route66.blues+github@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ files:
90
+ - .document
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - Rakefile
95
+ - ReadMe.md
96
+ - VERSION
97
+ - digit_delim.gemspec
98
+ - lib/digit_delim.rb
99
+ - test/helper.rb
100
+ - test/test_digit_delim.rb
101
+ homepage: http://github.com/mephistobooks/digit_delim
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A little num-string formatter, converter.
125
+ test_files: []