superfeature 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +1 -0
- data/lib/superfeature/price.rb +6 -0
- data/lib/superfeature/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1cb9113e0c87858b70dfd215f524b9359baf10cf69d51fbcadf5e80010e3929
|
|
4
|
+
data.tar.gz: 0c1b5ad5c8068a211300431b3e881fd164ef04dedc54ba9da4c263108145cdfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da1075eb85dfb9fa91f73ba8fc07c095997ddfa762599da8484ba546e07b64973c33dabe911151f86a5b10513cd52390828154dfde631bc2fff99b82945674eb
|
|
7
|
+
data.tar.gz: fa0bea7dda490f95f9be6fa2736858b526ba2247254d74e22b9f8986e9e42b78cb7d1de534833076045ae2dc3f72b0a92d0dd489522177c0a1c32838ac80cd4f
|
data/README.md
CHANGED
|
@@ -331,6 +331,7 @@ price.discount_percent(0.25) # => $75.00 (25% off)
|
|
|
331
331
|
price.discount("25%") # => $75.00 (parses string)
|
|
332
332
|
price.discount("$20") # => $80.00 (parses string)
|
|
333
333
|
price.discount(20) # => $80.00 (numeric = dollars)
|
|
334
|
+
price.to(80) # => $80.00 (set target price directly)
|
|
334
335
|
|
|
335
336
|
# Chain discounts
|
|
336
337
|
price = Superfeature::Price.new(100.00)
|
data/lib/superfeature/price.rb
CHANGED
|
@@ -45,6 +45,12 @@ module Superfeature
|
|
|
45
45
|
Price.new(new_amount, original: self, amount_precision: @amount_precision, percent_precision: @percent_precision)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Set the price to a specific amount (calculates discount from current amount)
|
|
49
|
+
# Price(300).to(200) is equivalent to Price(300).discount_fixed(100)
|
|
50
|
+
def to(new_amount)
|
|
51
|
+
discount_fixed([@amount - new_amount.to_f, 0].max)
|
|
52
|
+
end
|
|
53
|
+
|
|
48
54
|
# Apply a percentage discount (decimal, e.g., 0.25 for 25%)
|
|
49
55
|
def discount_percent(percent)
|
|
50
56
|
discount_amount = @amount * percent.to_f
|
data/lib/superfeature/version.rb
CHANGED