money-heuristics 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.travis.yml +25 -0
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +17 -0
- data/Gemfile +6 -0
- data/LICENSE +23 -0
- data/README.md +13 -0
- data/Rakefile +17 -0
- data/lib/money-heuristics.rb +6 -0
- data/lib/money-heuristics/analyzer.rb +84 -0
- data/lib/money-heuristics/heuristics.rb +19 -0
- data/lib/money-heuristics/search_tree.rb +62 -0
- data/lib/money-heuristics/string.rb +13 -0
- data/lib/money-heuristics/version.rb +3 -0
- data/money-heuristics.gemspec +29 -0
- data/spec/heuristics_spec.rb +162 -0
- data/spec/spec_helper.rb +28 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79f7a3d1ed519a875dca357a27c43edfa213f681
|
4
|
+
data.tar.gz: 18fbf4a233e688163c980f81c01fc95a38d43d99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29d56724b61912d83dbb54af05c4c7c0f45ffd74f97804da050b10996cc7ca84cfdbb94100b3668b11d84acefb3e07c9e3738f46ef119218c4ab94e225da9d28
|
7
|
+
data.tar.gz: b8f1d08cadadc95218bd28c759216861a994205f87839eefa95329ff3e7aca137317795c00b8a19debd1cc1d3b0a44a819a5181d36d6598aaa5c50a64704881c
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: m7vyhHNz7HTqdYSL90YbygyYNMQ2JO9E2
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Bundler
|
2
|
+
.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
pkg/*
|
5
|
+
bin/
|
6
|
+
|
7
|
+
# Rubinius
|
8
|
+
*.rbc
|
9
|
+
|
10
|
+
# YARD
|
11
|
+
.yardoc
|
12
|
+
yardoc/
|
13
|
+
doc/
|
14
|
+
|
15
|
+
# Project
|
16
|
+
.rbenv-version
|
17
|
+
.rbx
|
18
|
+
.rvmrc
|
19
|
+
.ruby-version
|
20
|
+
.ruby-gemset
|
21
|
+
|
22
|
+
# Spec artifacts
|
23
|
+
/coverage
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.5
|
7
|
+
- 2.3.1
|
8
|
+
- 2.4.0
|
9
|
+
- rbx-2
|
10
|
+
- jruby-9.0.5.0
|
11
|
+
- jruby-9.1.2.0
|
12
|
+
- ruby-head
|
13
|
+
- jruby-head
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
- rvm: jruby-head
|
18
|
+
- rvm: rbx-2
|
19
|
+
fast_finish: true
|
20
|
+
script: bundle exec rspec spec
|
21
|
+
notifications:
|
22
|
+
email:
|
23
|
+
- semmons99@gmail.com
|
24
|
+
- andreas@aloop.org
|
25
|
+
- weppos@weppos.net
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Contribution Guidelines
|
2
|
+
|
3
|
+
## Steps
|
4
|
+
|
5
|
+
1. Fork [the repo](https://github.com/RubyMoney/money-heuristics)
|
6
|
+
2. Grab dependencies: `bundle install`
|
7
|
+
3. Make sure everything is working: `bundle exec rake spec`
|
8
|
+
4. Make your changes
|
9
|
+
5. Test your changes
|
10
|
+
5. Create a Pull Request
|
11
|
+
6. Celebrate!!!!!
|
12
|
+
|
13
|
+
## Notes
|
14
|
+
|
15
|
+
When contributing, please make sure to update the CHANGELOG and AUTHORS files
|
16
|
+
when you submit your pull request. Upon merging of your first pull request,
|
17
|
+
you will be given commit access to the repository.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2005 Tobias Lutke
|
4
|
+
Copyright (c) 2008 Phusion
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# RubyMoney - Money Heuristics
|
2
|
+
|
3
|
+
This is a module for heuristic analysis of the string input for the
|
4
|
+
[money gem](https://github.com/RubyMoney/money). It was formerly part of the gem.
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/money-heuristics.svg)](https://rubygems.org/gems/money-heuristics)
|
7
|
+
[![Build Status](https://travis-ci.org/RubyMoney/money-heuristics.svg?branch=master)](https://travis-ci.org/RubyMoney/money-heuristics)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/RubyMoney/money-heuristics/badge.svg?branch=master)](https://coveralls.io/github/RubyMoney/money-heuristics?branch=master)
|
9
|
+
[![License](https://img.shields.io/github/license/RubyMoney/money-heuristics.svg)](https://opensource.org/licenses/MIT)
|
10
|
+
|
11
|
+
## Contributing
|
12
|
+
|
13
|
+
See the [Contribution Guidelines](https://github.com/RubyMoney/money-heuristics/blob/master/CONTRIBUTING.md)
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/clean"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
CLOBBER.include('doc', '.yardoc')
|
6
|
+
|
7
|
+
require "yard"
|
8
|
+
|
9
|
+
YARD::Rake::YardocTask.new do |t|
|
10
|
+
t.options << "--files" << "CHANGELOG.md,LICENSE"
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
|
+
t.fail_on_error = false
|
15
|
+
end
|
16
|
+
|
17
|
+
task default: :spec
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module MoneyHeuristics
|
2
|
+
class Analyzer
|
3
|
+
attr_reader :search_tree, :words
|
4
|
+
attr_accessor :str, :currencies
|
5
|
+
|
6
|
+
def initialize(str, search_tree)
|
7
|
+
@str = (str || '').dup
|
8
|
+
@search_tree = search_tree
|
9
|
+
@currencies = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def process
|
13
|
+
format
|
14
|
+
return [] if str.empty?
|
15
|
+
|
16
|
+
search_by_symbol
|
17
|
+
search_by_iso_code
|
18
|
+
search_by_name
|
19
|
+
|
20
|
+
prepare_reply
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def format
|
26
|
+
str.gsub!(/[\r\n\t]/,'')
|
27
|
+
str.gsub!(/[0-9][\.,:0-9]*[0-9]/,'')
|
28
|
+
str.gsub!(/[0-9]/, '')
|
29
|
+
str.downcase!
|
30
|
+
@words = str.unaccent.split
|
31
|
+
@words.each {|word| word.chomp!('.'); word.chomp!(',') }
|
32
|
+
end
|
33
|
+
|
34
|
+
def search_by_symbol
|
35
|
+
words.each do |word|
|
36
|
+
if found = search_tree[:by_symbol][word]
|
37
|
+
currencies.concat(found)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def search_by_iso_code
|
43
|
+
words.each do |word|
|
44
|
+
if found = search_tree[:by_iso_code][word]
|
45
|
+
currencies.concat(found)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def search_by_name
|
51
|
+
# remember, the search tree by name is a construct of branches and leaf!
|
52
|
+
# We need to try every combination of words within the sentence, so we
|
53
|
+
# end up with a x^2 equation, which should be fine as most names are either
|
54
|
+
# one or two words, and this is multiplied with the words of given sentence
|
55
|
+
|
56
|
+
search_words = words.dup
|
57
|
+
|
58
|
+
while search_words.length > 0
|
59
|
+
root = search_tree[:by_name]
|
60
|
+
|
61
|
+
search_words.each do |word|
|
62
|
+
if root = root[word]
|
63
|
+
if root[:value]
|
64
|
+
currencies.concat(root[:value])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
search_words.delete_at(0)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def prepare_reply
|
76
|
+
codes = currencies.map do |currency|
|
77
|
+
currency[:iso_code]
|
78
|
+
end
|
79
|
+
codes.uniq!
|
80
|
+
codes.sort!
|
81
|
+
codes
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'money-heuristics/analyzer'
|
2
|
+
require 'money-heuristics/search_tree'
|
3
|
+
|
4
|
+
module MoneyHeuristics
|
5
|
+
module Heuristics
|
6
|
+
# An robust and efficient algorithm for finding currencies in
|
7
|
+
# text. Using several algorithms it can find symbols, iso codes and
|
8
|
+
# even names of currencies.
|
9
|
+
# Although not recommendable, it can also attempt to find the given
|
10
|
+
# currency in an entire sentence
|
11
|
+
#
|
12
|
+
# Returns: Array (matched results)
|
13
|
+
def analyze(str)
|
14
|
+
@_heuristics_search_tree ||= MoneyHeuristics::SearchTree.new(table).build
|
15
|
+
|
16
|
+
return MoneyHeuristics::Analyzer.new(str, @_heuristics_search_tree).process
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module MoneyHeuristics
|
2
|
+
class SearchTree
|
3
|
+
def initialize(currency_data)
|
4
|
+
@currency_data = currency_data
|
5
|
+
end
|
6
|
+
|
7
|
+
# Build a search tree from the currency database
|
8
|
+
def build
|
9
|
+
{
|
10
|
+
by_symbol: currencies_by_symbol,
|
11
|
+
by_iso_code: currencies_by_iso_code,
|
12
|
+
by_name: currencies_by_name
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :currency_data
|
19
|
+
|
20
|
+
def currencies_by_symbol
|
21
|
+
{}.tap do |result|
|
22
|
+
currency_data.each do |_, currency|
|
23
|
+
symbol = (currency[:symbol]||"").downcase
|
24
|
+
symbol.chomp!('.')
|
25
|
+
(result[symbol] ||= []) << currency
|
26
|
+
|
27
|
+
(currency[:alternate_symbols] || []).each do |ac|
|
28
|
+
ac = ac.downcase
|
29
|
+
ac.chomp!('.')
|
30
|
+
(result[ac] ||= []) << currency
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def currencies_by_iso_code
|
37
|
+
{}.tap do |result|
|
38
|
+
currency_data.each do |_, currency|
|
39
|
+
(result[currency[:iso_code].downcase] ||= []) << currency
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def currencies_by_name
|
45
|
+
{}.tap do |result|
|
46
|
+
currency_data.each do |_, currency|
|
47
|
+
name_parts = currency[:name].unaccent.downcase.split
|
48
|
+
name_parts.each {|part| part.chomp!('.')}
|
49
|
+
|
50
|
+
# construct one branch per word
|
51
|
+
root = result
|
52
|
+
while name_part = name_parts.shift
|
53
|
+
root = (root[name_part] ||= {})
|
54
|
+
end
|
55
|
+
|
56
|
+
# the leaf is a currency
|
57
|
+
(root[:value] ||= []) << currency
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sixarm_ruby_unaccent'
|
2
|
+
|
3
|
+
# Overwrites unaccent method of sixarm_ruby_unaccent.
|
4
|
+
class String
|
5
|
+
def unaccent
|
6
|
+
accentmap = ACCENTMAP
|
7
|
+
accentmap.delete("\u{0142}") # Delete ł symbol from ACCENTMAP used in PLN currency
|
8
|
+
accentmap.delete("\u{010D}") # Delete č symbol from ACCENTMAP used in CZK currency
|
9
|
+
accentmap.delete("\u{FDFC}") # Delete ﷼ symbol from ACCENTMAP used in IRR, SAR and YER currencies
|
10
|
+
accentmap.delete("\u{20A8}") # Delete ₨ symbol from ACCENTMAP used in INR, LKR, MUR, NPR, PKR and SCR currencies
|
11
|
+
split(//u).map {|c| accentmap[c] || c }.join("")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "money-heuristics/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "money-heuristics"
|
8
|
+
s.version = MoneyHeuristics::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Shane Emmons']
|
11
|
+
s.email = ['shane@emmons.io']
|
12
|
+
s.homepage = 'https://rubymoney.github.io/money-heuristics'
|
13
|
+
s.summary = 'Heuristic module for for the money gem'
|
14
|
+
s.description = 'This is a module for heuristic analysis of the string input for the money gem. It was formerly part of the gem.'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.add_dependency 'money', '>= 6.8.2'
|
18
|
+
s.add_dependency 'sixarm_ruby_unaccent', ['>= 1.1.1', '< 2']
|
19
|
+
|
20
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec", "~> 3.4.0"
|
23
|
+
s.add_development_dependency "yard", "~> 0.8"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split($/)
|
26
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe MoneyHeuristics do
|
4
|
+
describe "#analyze_string" do
|
5
|
+
let(:it) { Money::Currency }
|
6
|
+
|
7
|
+
it "is not affected by blank characters and numbers" do
|
8
|
+
expect(it.analyze('123')).to eq []
|
9
|
+
expect(it.analyze('\n123 \t')).to eq []
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns nothing when given nothing" do
|
13
|
+
expect(it.analyze('')).to eq []
|
14
|
+
expect(it.analyze(nil)).to eq []
|
15
|
+
end
|
16
|
+
|
17
|
+
it "finds a currency by use of its symbol" do
|
18
|
+
expect(it.analyze('zł')).to eq ['PLN']
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is not affected by trailing dot" do
|
22
|
+
expect(it.analyze('zł.')).to eq ['PLN']
|
23
|
+
end
|
24
|
+
|
25
|
+
it "finds match even if has numbers after" do
|
26
|
+
expect(it.analyze('zł 123')).to eq ['PLN']
|
27
|
+
end
|
28
|
+
|
29
|
+
it "finds match even if has numbers before" do
|
30
|
+
expect(it.analyze('123 zł')).to eq ['PLN']
|
31
|
+
end
|
32
|
+
|
33
|
+
it "find match even if symbol is next to number" do
|
34
|
+
expect(it.analyze('300zł')).to eq ['PLN']
|
35
|
+
end
|
36
|
+
|
37
|
+
it "finds match even if has numbers with delimiters" do
|
38
|
+
expect(it.analyze('zł 123,000.50')).to eq ['PLN']
|
39
|
+
expect(it.analyze('zł123,000.50')).to eq ['PLN']
|
40
|
+
end
|
41
|
+
|
42
|
+
it "finds currencies with dots in symbols" do
|
43
|
+
expect(it.analyze('L.E.')).to eq ['EGP']
|
44
|
+
end
|
45
|
+
|
46
|
+
it "finds by name" do
|
47
|
+
expect(it.analyze('1900 bulgarian lev')).to eq ['BGN']
|
48
|
+
expect(it.analyze('Swedish Krona')).to eq ['SEK']
|
49
|
+
end
|
50
|
+
|
51
|
+
it "Finds several currencies when several match" do
|
52
|
+
r = it.analyze('$400')
|
53
|
+
expect(r).to include("ARS")
|
54
|
+
expect(r).to include("USD")
|
55
|
+
expect(r).to include("NZD")
|
56
|
+
|
57
|
+
r = it.analyze('9000 £')
|
58
|
+
expect(r).to include("GBP")
|
59
|
+
expect(r).to include("SHP")
|
60
|
+
expect(r).to include("SYP")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should use alternate symbols" do
|
64
|
+
expect(it.analyze('US$')).to eq ['USD']
|
65
|
+
end
|
66
|
+
|
67
|
+
it "finds a currency by use of its iso code" do
|
68
|
+
expect(it.analyze('USD 200')).to eq ['USD']
|
69
|
+
end
|
70
|
+
|
71
|
+
it "finds currencies in the middle of a sentence!" do
|
72
|
+
expect(it.analyze('It would be nice to have 10000 Albanian lek by tomorrow!')).to eq ['ALL']
|
73
|
+
end
|
74
|
+
|
75
|
+
it "finds several currencies in the same text!" do
|
76
|
+
expect(it.analyze("10EUR is less than 100:- but really, I want US$1")).to eq ['EUR', 'SEK', 'USD']
|
77
|
+
end
|
78
|
+
|
79
|
+
it "find currencies with normal characters in name using unaccent" do
|
80
|
+
expect(it.analyze("10 Nicaraguan Cordoba")).to eq ["NIO"]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "find currencies with special characters in name using unaccent" do
|
84
|
+
expect(it.analyze("10 Nicaraguan Córdoba")).to eq ["NIO"]
|
85
|
+
end
|
86
|
+
|
87
|
+
it "find currencies with special symbols using unaccent" do
|
88
|
+
expect(it.analyze("ل.س")).not_to eq []
|
89
|
+
expect(it.analyze("R₣")).not_to eq []
|
90
|
+
expect(it.analyze("ரூ")).not_to eq []
|
91
|
+
expect(it.analyze("රු")).not_to eq []
|
92
|
+
expect(it.analyze("сом")).not_to eq []
|
93
|
+
expect(it.analyze("圓")).not_to eq []
|
94
|
+
expect(it.analyze("円")).not_to eq []
|
95
|
+
expect(it.analyze("৳")).not_to eq []
|
96
|
+
expect(it.analyze("૱")).not_to eq []
|
97
|
+
expect(it.analyze("௹")).not_to eq []
|
98
|
+
expect(it.analyze("रु")).not_to eq []
|
99
|
+
expect(it.analyze("ש״ח")).not_to eq []
|
100
|
+
expect(it.analyze("元")).not_to eq []
|
101
|
+
expect(it.analyze("¢")).not_to eq []
|
102
|
+
expect(it.analyze("£")).not_to eq []
|
103
|
+
expect(it.analyze("€")).not_to eq []
|
104
|
+
expect(it.analyze("¥")).not_to eq []
|
105
|
+
expect(it.analyze("د.إ")).not_to eq []
|
106
|
+
expect(it.analyze("؋")).not_to eq []
|
107
|
+
expect(it.analyze("դր.")).not_to eq []
|
108
|
+
expect(it.analyze("ƒ")).not_to eq []
|
109
|
+
expect(it.analyze("₼")).not_to eq []
|
110
|
+
expect(it.analyze("৳")).not_to eq []
|
111
|
+
expect(it.analyze("лв")).not_to eq []
|
112
|
+
expect(it.analyze("лев")).not_to eq []
|
113
|
+
expect(it.analyze("дин")).not_to eq []
|
114
|
+
expect(it.analyze("ب.د")).not_to eq []
|
115
|
+
expect(it.analyze("₡")).not_to eq []
|
116
|
+
expect(it.analyze("Kč")).not_to eq []
|
117
|
+
expect(it.analyze("د.ج")).not_to eq []
|
118
|
+
expect(it.analyze("ج.م")).not_to eq []
|
119
|
+
expect(it.analyze("ლ")).not_to eq []
|
120
|
+
expect(it.analyze("₵")).not_to eq []
|
121
|
+
expect(it.analyze("₪")).not_to eq []
|
122
|
+
expect(it.analyze("₹")).not_to eq []
|
123
|
+
expect(it.analyze("ع.د")).not_to eq []
|
124
|
+
expect(it.analyze("﷼")).not_to eq []
|
125
|
+
expect(it.analyze("د.ا")).not_to eq []
|
126
|
+
expect(it.analyze("៛")).not_to eq []
|
127
|
+
expect(it.analyze("₩")).not_to eq []
|
128
|
+
expect(it.analyze("د.ك")).not_to eq []
|
129
|
+
expect(it.analyze("〒")).not_to eq []
|
130
|
+
expect(it.analyze("₭")).not_to eq []
|
131
|
+
expect(it.analyze("ل.ل")).not_to eq []
|
132
|
+
expect(it.analyze("₨")).not_to eq []
|
133
|
+
expect(it.analyze("ل.د")).not_to eq []
|
134
|
+
expect(it.analyze("د.م.")).not_to eq []
|
135
|
+
expect(it.analyze("ден")).not_to eq []
|
136
|
+
expect(it.analyze("₮")).not_to eq []
|
137
|
+
expect(it.analyze("₦")).not_to eq []
|
138
|
+
expect(it.analyze("C$")).not_to eq []
|
139
|
+
expect(it.analyze("ر.ع.")).not_to eq []
|
140
|
+
expect(it.analyze("₱")).not_to eq []
|
141
|
+
expect(it.analyze("zł")).not_to eq []
|
142
|
+
expect(it.analyze("₲")).not_to eq []
|
143
|
+
expect(it.analyze("ر.ق")).not_to eq []
|
144
|
+
expect(it.analyze("РСД")).not_to eq []
|
145
|
+
expect(it.analyze("₽")).not_to eq []
|
146
|
+
expect(it.analyze("ر.س")).not_to eq []
|
147
|
+
expect(it.analyze("฿")).not_to eq []
|
148
|
+
expect(it.analyze("د.ت")).not_to eq []
|
149
|
+
expect(it.analyze("T$")).not_to eq []
|
150
|
+
expect(it.analyze("₺")).not_to eq []
|
151
|
+
expect(it.analyze("₴")).not_to eq []
|
152
|
+
expect(it.analyze("₫")).not_to eq []
|
153
|
+
expect(it.analyze("B⃦")).not_to eq []
|
154
|
+
expect(it.analyze("₤")).not_to eq []
|
155
|
+
expect(it.analyze("ރ")).not_to eq []
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should function with unicode characters" do
|
159
|
+
expect(it.analyze("10 դր.")).to eq ["AMD"]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "coveralls"
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
5
|
+
require "rspec"
|
6
|
+
require "money"
|
7
|
+
|
8
|
+
I18n.enforce_available_locales = false
|
9
|
+
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.order = :random
|
12
|
+
c.filter_run :focus
|
13
|
+
c.run_all_when_everything_filtered = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def reset_i18n
|
17
|
+
I18n.backend = I18n::Backend::Simple.new
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.shared_context "with infinite precision", :infinite_precision do
|
21
|
+
before do
|
22
|
+
Money.infinite_precision = true
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
Money.infinite_precision = false
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: money-heuristics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shane Emmons
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: money
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.8.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.8.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sixarm_ruby_unaccent
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.1
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.1
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.4.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.4.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: yard
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.8'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.8'
|
103
|
+
description: This is a module for heuristic analysis of the string input for the money
|
104
|
+
gem. It was formerly part of the gem.
|
105
|
+
email:
|
106
|
+
- shane@emmons.io
|
107
|
+
executables: []
|
108
|
+
extensions: []
|
109
|
+
extra_rdoc_files: []
|
110
|
+
files:
|
111
|
+
- ".coveralls.yml"
|
112
|
+
- ".gitignore"
|
113
|
+
- ".rspec"
|
114
|
+
- ".travis.yml"
|
115
|
+
- CHANGELOG.md
|
116
|
+
- CONTRIBUTING.md
|
117
|
+
- Gemfile
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- lib/money-heuristics.rb
|
122
|
+
- lib/money-heuristics/analyzer.rb
|
123
|
+
- lib/money-heuristics/heuristics.rb
|
124
|
+
- lib/money-heuristics/search_tree.rb
|
125
|
+
- lib/money-heuristics/string.rb
|
126
|
+
- lib/money-heuristics/version.rb
|
127
|
+
- money-heuristics.gemspec
|
128
|
+
- spec/heuristics_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://rubymoney.github.io/money-heuristics
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.6.8
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Heuristic module for for the money gem
|
154
|
+
test_files:
|
155
|
+
- spec/heuristics_spec.rb
|
156
|
+
- spec/spec_helper.rb
|