numeric_nation_input 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +10 -0
- data/lib/numeric_nation_input.rb +17 -0
- data/lib/numeric_nation_input/version.rb +3 -0
- data/numeric_nation_input.gemspec +26 -0
- data/test/numeric_nation_input_test.rb +37 -0
- data/test/test_helper.rb +14 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3acc3381752e29620612aaf90d63611b66b32d91
|
4
|
+
data.tar.gz: c902e40acf7a1f4cdc8bf7f105eedf36e66dc501
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 977b0ae141f63c1d835a5f9da23b97eb76d8eeb16a13ab1d38f47057b05e8cb7e59b019b91577a23d40167ee30d3a85add37f81660f246ded419f6970057431e
|
7
|
+
data.tar.gz: 4c87096b89fffaca31b1368af985dc20bc55741bb91f5b790d9264c6ae3d1908e129983edc6b94f39b30fe69f7cdb6d9f01d37f908518cb681cb15b7fd4ecef0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 NetBrick s.r.o.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Numeric Nation Input Gem for Rails 3.2
|
2
|
+
[![Build Status](https://travis-ci.org/netbrick/numeric_nation_input.png?branch=master)](https://travis-ci.org/netbrick/numeric_nation_input)
|
3
|
+
|
4
|
+
## Info
|
5
|
+
|
6
|
+
Allow `,` as decimal part delimiter for AR's float typecasting from string.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# Gemfile
|
12
|
+
gem "numeric_nation_input", git: "http://github.com/netbrick/numeric_nation_input.git"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class TestModel < ActiveRecord::Base
|
19
|
+
attr_accessible :attr1, :attr2
|
20
|
+
|
21
|
+
numeric_nation_input :attr1, :attr2
|
22
|
+
end
|
23
|
+
|
24
|
+
model = TestModel.new(attr1: "1025,45")
|
25
|
+
model.attr1 #=> 1025.45 (Float)
|
26
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module NumericNationInput
|
4
|
+
def self.normalize(number)
|
5
|
+
number.gsub(',', '.')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ActiveRecord::Base
|
10
|
+
def self.numeric_nation_input(*fields)
|
11
|
+
fields.each do |field|
|
12
|
+
define_method("#{field}=") do |value|
|
13
|
+
self[field] = value.is_a?(String) ? NumericNationInput.normalize(value) : value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/numeric_nation_input/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'numeric_nation_input'
|
6
|
+
s.version = NumericNationInput::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = %w(Jan Strnádek Josef Šimánek)
|
9
|
+
s.email = %w(jan.strnadek@gmail.com retro@ballgag.cz)
|
10
|
+
s.homepage = 'https://github.com/netbrick/numeric_nation_input'
|
11
|
+
s.summary = 'Implementation of saving nation numerc inputs in AR'
|
12
|
+
s.description = "Implementation of saving nation numerc inputs in AR"
|
13
|
+
|
14
|
+
s.required_rubygems_version = '>= 1.3.6'
|
15
|
+
|
16
|
+
s.add_dependency 'activerecord', '~> 3.2'
|
17
|
+
|
18
|
+
s.add_development_dependency 'bundler', '>= 1.0.0'
|
19
|
+
s.add_development_dependency 'minitest'
|
20
|
+
s.add_development_dependency 'sqlite3'
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.executables = `git ls-files`.split("\n").map { |f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
|
25
|
+
s.require_path = 'lib'
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NumericNationInputTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@model = TestModel.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_valid_model_numericality
|
9
|
+
@model.number = "1,5"
|
10
|
+
assert @model.valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_invalid_model_numericality
|
14
|
+
@model.number = "not a number"
|
15
|
+
refute @model.valid?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_constructor_is_typecasting
|
19
|
+
@model = TestModel.new(number: "1,5")
|
20
|
+
assert_equal 1.5, @model.number
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_casting_of_comma_to_number
|
24
|
+
@model.number = "1,5"
|
25
|
+
assert_equal 1.5, @model.number
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_casting_of_point_to_number
|
29
|
+
@model.number = "1.5"
|
30
|
+
assert_equal 1.5, @model.number
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_casting_of_number_to_number
|
34
|
+
@model.number = 1.5
|
35
|
+
assert_equal 1.5, @model.number
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'numeric_nation_input'
|
4
|
+
|
5
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'test/test.sqlite3'
|
6
|
+
|
7
|
+
ActiveRecord::Migration.create_table :test_models do |t|
|
8
|
+
t.float :number
|
9
|
+
end rescue nil # poor's man schema
|
10
|
+
|
11
|
+
class TestModel < ::ActiveRecord::Base
|
12
|
+
numeric_nation_input :number
|
13
|
+
validates :number, numericality: true
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: numeric_nation_input
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan
|
8
|
+
- Strnádek
|
9
|
+
- Josef
|
10
|
+
- Šimánek
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activerecord
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: minitest
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sqlite3
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: rake
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
description: Implementation of saving nation numerc inputs in AR
|
87
|
+
email:
|
88
|
+
- jan.strnadek@gmail.com
|
89
|
+
- retro@ballgag.cz
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- .gitignore
|
95
|
+
- .travis.yml
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- lib/numeric_nation_input.rb
|
101
|
+
- lib/numeric_nation_input/version.rb
|
102
|
+
- numeric_nation_input.gemspec
|
103
|
+
- test/numeric_nation_input_test.rb
|
104
|
+
- test/test_helper.rb
|
105
|
+
homepage: https://github.com/netbrick/numeric_nation_input
|
106
|
+
licenses: []
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.3.6
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Implementation of saving nation numerc inputs in AR
|
128
|
+
test_files: []
|