better-money 0.0.1
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.
- checksums.yaml +15 -0
- data/lib/better_money/analyzer.rb +44 -0
- data/lib/better_money/version.rb +3 -0
- data/lib/better_money.rb +7 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGQ4ZDQyYjM0ODUzZjFlMDk3NWI3NDI1YmMyMjZiMGFlZGVmM2QyZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjVkNGU0NzBkNmY5MmE4MGVlYzI1ZWI5NjNjYjFhMWI0OTUxOWIxMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTZlNzIzNDdlODIwZDk1Y2ZiNGY2MGJjN2Y0YjkzMWVkOTQ3MzVjMjc5MGU4
|
10
|
+
YjJlYmVhZWVhYzRmNjRmYmM3NWRlOGM5MmQyZTVkN2M0MWIyZDVkY2U2Nzk1
|
11
|
+
YWFjNDg4NDljN2M0NjRlZDM3ZjQxYTM0YTViYzQ2ODZiMjIxYjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjA4ZDI3ODc0MDA0ZWJhOGQxYzRkNzQyODIwYzQ1OGFhMmQ4YzliM2MxOTAz
|
14
|
+
ODZjOTNkYTdlMTRlMzQzMWQyMzFlMjVjNDFhODU3NTkyM2RhZTBjMDRmZWZj
|
15
|
+
YjE1NDYwOTQ0NzMxMGQ3Yzk3YjNiNDMxZTUyYjA3ODI5NDdiNDU=
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module BetterMoney
|
2
|
+
CURRENCY_SYMBOL = "$"
|
3
|
+
UNIT_SYMBOL = ["", "k", "M", "B", "T"]
|
4
|
+
SEPERATE_BY = 3
|
5
|
+
|
6
|
+
class Analyzer
|
7
|
+
def initialize(amount)
|
8
|
+
@amount = amount
|
9
|
+
end
|
10
|
+
|
11
|
+
def currency_symbol
|
12
|
+
@currency_symbol ||= CURRENCY_SYMBOL
|
13
|
+
end
|
14
|
+
|
15
|
+
def value
|
16
|
+
@value ||= find_value(@amount)
|
17
|
+
end
|
18
|
+
|
19
|
+
def unit_symbol
|
20
|
+
@unit_symbol ||= UNIT_SYMBOL[seperate_level]
|
21
|
+
end
|
22
|
+
|
23
|
+
def seperate_level
|
24
|
+
@seperate_level ||= find_seperate_level(@amount)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def find_seperate_level(amount)
|
29
|
+
cipher = amount.to_i.to_s.length
|
30
|
+
|
31
|
+
current_level = (cipher - 1) / SEPERATE_BY
|
32
|
+
maximum_level = UNIT_SYMBOL.length
|
33
|
+
|
34
|
+
[current_level, (maximum_level - 1)].min
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_value(amount)
|
38
|
+
divide_value = (10 ** SEPERATE_BY) ** seperate_level
|
39
|
+
|
40
|
+
result = amount.to_f / divide_value
|
41
|
+
result.round(2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/better_money.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: better-money
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sung-Hee Kang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Better money displanation
|
14
|
+
email: sungheee.kang@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/better_money.rb
|
20
|
+
- lib/better_money/version.rb
|
21
|
+
- lib/better_money/analyzer.rb
|
22
|
+
homepage: http://github.com/sungheekang/better-money
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Better money displanation
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|