number_prefix 0.1.0
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/MIT-LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +23 -0
- data/lib/number_prefix/number_helper.rb +28 -0
- data/lib/number_prefix/version.rb +9 -0
- data/lib/number_prefix.rb +8 -0
- data/test/number_prefix_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +74 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= NumberPrefix - Prefix numbers with a symbol
|
2
|
+
|
3
|
+
This is a ActionView::Helpers::NumberHelper module extension that implements a prefix feature.
|
4
|
+
With this library you can easily format numbers prefixed with a symbol (e.g. +38.13, $+/-12.13, -14.12).
|
5
|
+
|
6
|
+
== Installation (Rails 3 ready)
|
7
|
+
|
8
|
+
Add this line to your Gemfile
|
9
|
+
|
10
|
+
gem 'number_prefix'
|
11
|
+
|
12
|
+
== Examples
|
13
|
+
|
14
|
+
# Options
|
15
|
+
:prefix => boolean|string
|
16
|
+
:prefix_match => :positive|:negative|:any
|
17
|
+
|
18
|
+
# Test it
|
19
|
+
number_to_currency(-1938, :prefix => true)
|
20
|
+
number_to_percentage(234.4, :prefix => '+/-')
|
21
|
+
number_with_delimiter(-45, :prefix => '@', :prefix_match => :any)
|
22
|
+
number_with_precision(-57.3, :prefix => true, :prefix_match => :negative)
|
23
|
+
number_with_precision(0, :prefix => '!', :prefix_match => :any)
|
24
|
+
|
25
|
+
Note that you can use all {built-in options as well}[http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html]
|
26
|
+
|
27
|
+
Would you like to use these methods inside your model or controller? Add this to your class:
|
28
|
+
|
29
|
+
include ActionView::Helpers::NumberHelper
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the number_prefix plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the number_prefix plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'NumberPrefix'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
module NumberHelper
|
5
|
+
|
6
|
+
alias old_number_with_delimiter number_with_delimiter
|
7
|
+
def number_with_delimiter(number, options = {})
|
8
|
+
insert_prefix(old_number_with_delimiter(number, options), number, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def insert_prefix(nstr, number, options)
|
14
|
+
value = number.to_s.to_d
|
15
|
+
prefix = options[:prefix].present? && (value > 0 || value < 0 && options[:prefix_match] == :negative || options[:prefix_match] == :any)
|
16
|
+
simbol = options[:prefix] == true ? '+' : options[:prefix]
|
17
|
+
puts prefix
|
18
|
+
|
19
|
+
if prefix && nstr.present?
|
20
|
+
nstr.sub(/(-|[0-9])/, simbol+'\1')
|
21
|
+
else
|
22
|
+
nstr
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: number_prefix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristijan Sedlak
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-10 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: This is a ActionView:Helper:NumberHelper module extension that implements a number prefix feature. With this library you can easily format numbers prefixed with a simbol (e.g. +38.13, $+/-12.13, -14.12).
|
22
|
+
email: xpepermint@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
- MIT-LICENSE
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- lib/number_prefix/number_helper.rb
|
33
|
+
- lib/number_prefix/version.rb
|
34
|
+
- lib/number_prefix.rb
|
35
|
+
- test/number_prefix_test.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
- README.rdoc
|
38
|
+
- MIT-LICENSE
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/xpepermint/number_prefix
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.rdoc
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: NumberPrefix - Prefix numbers with a simbol.
|
73
|
+
test_files: []
|
74
|
+
|