formatting 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eedbb12f830e0efcd539953a2161c5e56b521fe
4
- data.tar.gz: 27a038999934b49bce503907e1aec13307729c56
3
+ metadata.gz: 3955f66b2db50346419ee47e7504648cf7b521f9
4
+ data.tar.gz: fe2d09e425d414518a440950da09e68516091d90
5
5
  SHA512:
6
- metadata.gz: ee6f14dcfc48e9ad749c57e86fb221227bda44312ae1dbc20072bbd58d4afec0e1ec8f22a567ff98671133dfbf6da642b08b6021523f11423067a4fc03356cd9
7
- data.tar.gz: 1228b163c277ee2d7f85e833fa9c92c975876e56e9a8f4dbb7d1bf395eb62d7d09d88a57376544710141c9e94928f0088b93e1b80f294d331e9ecaf6d4d29b07
6
+ metadata.gz: d67d72c11459baa553c190d991fc4eee953d7e3f523f2ca71a6cd3aff8e3d1c6915bf4c80c4d9b9ae7f0b30149c3fde1472394215cb6dd38813466af68809b71
7
+ data.tar.gz: 049d9d2cce7c44b6a20e8f611d07215241de9b5521090a28a0d19b25faade22a169bd019ee80be316be9365e0464cf295295df05accba251cd7435a10b6272eb
data/README.md CHANGED
@@ -83,3 +83,4 @@ Or install it yourself as:
83
83
  * Don't depend on `i18n`?
84
84
  * Rename? This name is boring and also generic enough that collisions seem likely.
85
85
  * Document options
86
+ * Change some defaults: round: 2, min_decimals: 2
@@ -1,8 +1,14 @@
1
1
  module Formatting
2
+ class NotARecordError < StandardError; end
3
+
2
4
  module Currency
3
5
  include Number
4
6
 
5
7
  def format_currency(record, amount_or_method, opts = {})
8
+ if record.is_a?(Symbol)
9
+ raise NotARecordError, "Expected an object that could tell us its currency; got #{record.inspect}"
10
+ end
11
+
6
12
  opts = Formatting.defaults.merge(opts)
7
13
 
8
14
  format_string = opts.fetch(:format, "<amount> <currency>")
@@ -17,6 +23,8 @@ module Formatting
17
23
  amount = amount_or_method
18
24
  end
19
25
 
26
+ amount = 0 if amount.nil?
27
+
20
28
  amount = format_number(amount, opts)
21
29
  apply_format_string(format_string, amount, currency)
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module Formatting
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,6 +21,14 @@ describe Formatting do
21
21
  item.stub(price: 2)
22
22
  expect_formatted(item, :price).to eq space_to_nbsp("2.0")
23
23
  end
24
+
25
+ it "complains if the 'record' looks like a method name (a likely mistake)" do
26
+ expect { Formatting.format_currency(:item, 123) }.to raise_error(Formatting::NotARecordError)
27
+ end
28
+ end
29
+
30
+ it "treats nil as 0" do
31
+ expect_formatted(item, nil).to include space_to_nbsp("0.0")
24
32
  end
25
33
 
26
34
  context "formatting" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh