cheddar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cheddar.rb +80 -49
- metadata +9 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 46e6d76d91fcc1401a912c50c6a01a0cb1d2d2b9
|
4
|
+
data.tar.gz: bcbbd764a9fc97eec108dffbbd8bed5417121315
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a11b959c6cd0c0abeb0173c73632845b0921515eee0e5c7277da4b7763227cf9175928ddfcf1975b312a27906eef50a3e59cff41d510761757dd106543d156a
|
7
|
+
data.tar.gz: d9a3f93df28e8ac9cc7ee1879a9c5bccaf6255eb043777833a649d5066db87afb048a40bc682fbd12b467f573a1616533e71b73a24a4c1c9ff141e8f548f583c
|
data/lib/cheddar.rb
CHANGED
@@ -1,60 +1,91 @@
|
|
1
|
-
class
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
class Cheddar
|
2
|
+
|
3
|
+
attr_accessor :enabled_dialects
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@mapping = {}
|
7
|
+
@enabled_dialects = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def available_dialects
|
11
|
+
@mapping.keys
|
12
|
+
end
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
slang = {
|
12
|
-
bacon: 1,
|
13
|
-
benjamin: 100,
|
14
|
-
'big ones' => 1000,
|
15
|
-
bills: 1,
|
16
|
-
bread: 1,
|
17
|
-
buck: 1,
|
18
|
-
cabbage: 1,
|
19
|
-
cash: 1,
|
20
|
-
cheddar: 1,
|
21
|
-
cheese: 1,
|
22
|
-
clams: 1,
|
23
|
-
'c-note' => 100,
|
24
|
-
'dead presidents' => 1,
|
25
|
-
dolla: 1,
|
26
|
-
dollar: 1,
|
27
|
-
'double sawbuck' => 20,
|
28
|
-
dough: 1,
|
29
|
-
fin: 5,
|
30
|
-
green: 1,
|
31
|
-
greenback: 1,
|
32
|
-
jackson: 100,
|
33
|
-
kale: 1,
|
34
|
-
large: 1000,
|
35
|
-
lettuce: 1,
|
36
|
-
'long green' => 1,
|
37
|
-
loot: 1,
|
38
|
-
moolah: 1,
|
39
|
-
paper: 1,
|
40
|
-
potato: 1,
|
41
|
-
potatoes: 1,
|
42
|
-
sawbuck: 10,
|
43
|
-
scratch: 1,
|
44
|
-
scrip: 1,
|
45
|
-
twankie: 100
|
46
|
-
}
|
47
|
-
mapping.merge! slang
|
14
|
+
def cheddarize
|
15
|
+
String.send(:define_method, :human_to_number) do
|
16
|
+
Cheddar.parse(self)
|
48
17
|
end
|
18
|
+
end
|
49
19
|
|
50
|
-
|
20
|
+
def define(word, number)
|
21
|
+
@mapping[@current_dialect] ||= {}
|
22
|
+
@mapping[@current_dialect][word] = number
|
23
|
+
end
|
24
|
+
|
25
|
+
def dialect(dia)
|
26
|
+
@current_dialect = dia
|
27
|
+
yield self.class.instance if block_given?
|
28
|
+
@mapping[dia]
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse(string)
|
32
|
+
str = string.downcase
|
51
33
|
|
52
|
-
|
53
|
-
|
34
|
+
@enabled_dialects.each do |d|
|
35
|
+
@mapping[d].each do |num_name, value|
|
36
|
+
unless num_name.is_a? Regexp
|
37
|
+
str.gsub!(Regexp.new("(^|\s)#{num_name.to_s}($|\s)"), "* #{value}")
|
38
|
+
else
|
39
|
+
str.gsub!(num_name, "* #{value}")
|
40
|
+
end
|
41
|
+
end
|
54
42
|
end
|
55
43
|
|
56
44
|
str.gsub!(/[^\d\*\.]/, '')
|
57
45
|
|
58
46
|
eval(str)
|
59
47
|
end
|
48
|
+
|
49
|
+
def self.cheddarize
|
50
|
+
self.instance.cheddarize
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.config
|
54
|
+
yield self.instance if block_given?
|
55
|
+
self.instance
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.instance
|
59
|
+
@instance ||= new
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.parse(string)
|
63
|
+
self.instance.parse(string)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Cheddar.config do |c|
|
68
|
+
|
69
|
+
c.dialect(:en_us) do |d|
|
70
|
+
d.define :hundred, 100
|
71
|
+
d.define :thousand, 1000
|
72
|
+
%w(m b tr quadr quint sext sept oct non dec undec duodec tredec quattuordec quindec sexdec septemdec octodec novemdec vigint).inject(1000) do |m,p|
|
73
|
+
d.define "#{p}illion", 1000 * m
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
c.dialect(:slang_us) do |d|
|
78
|
+
%w(bacon bills bread buck cabbage cash cheddar cheese clams dolla dollar dough green greenback kale lettuce loot moolah paper potato potatoes scratch scrip).each { |p| d.define p, 1 }
|
79
|
+
%w(benjamin c-note jackson twankie).each { |p| d.define p, 100 }
|
80
|
+
d.define 'dead presidents', 1
|
81
|
+
d.define 'long green', 1
|
82
|
+
d.define 'fin', 5
|
83
|
+
d.define 'sawbuck', 10
|
84
|
+
d.define 'double sawbuck', 20
|
85
|
+
d.define 'large', 1000
|
86
|
+
d.define 'big ones', 1000
|
87
|
+
end
|
88
|
+
|
89
|
+
c.enabled_dialects = [:en_us, :slang_us]
|
90
|
+
|
60
91
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheddar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kenny Parnell
|
@@ -10,37 +9,36 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2012-
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
description:
|
14
|
+
description: Convert human readable strings to numbers. Also handles gangster terminology.
|
16
15
|
email: k.parnell@gmail.com
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
20
|
- lib/cheddar.rb
|
22
|
-
homepage: http://github.com/
|
21
|
+
homepage: http://github.com/kennyp/cheddar
|
23
22
|
licenses: []
|
23
|
+
metadata: {}
|
24
24
|
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
28
28
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
29
|
requirements:
|
31
|
-
- -
|
30
|
+
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
34
|
requirements:
|
37
|
-
- -
|
35
|
+
- - ">="
|
38
36
|
- !ruby/object:Gem::Version
|
39
37
|
version: '0'
|
40
38
|
requirements: []
|
41
39
|
rubyforge_project:
|
42
|
-
rubygems_version:
|
40
|
+
rubygems_version: 2.2.2
|
43
41
|
signing_key:
|
44
|
-
specification_version:
|
42
|
+
specification_version: 4
|
45
43
|
summary: Little library to convert human readable strings to numbers.
|
46
44
|
test_files: []
|