lib/atol/request/post_document/item/body.rb in atol-0.3 vs lib/atol/request/post_document/item/body.rb in atol-0.4
- old
+ new
@@ -4,23 +4,35 @@
module Request
class PostDocument
module Item
class Body
def initialize(name:, price:, quantity: 1, config: nil)
- @config = config || Atol.config
-
raise Atol::ZeroItemQuantityError if quantity.to_i.zero?
- @body = Hash[]
- @body[:name] = name
- @body[:price] = price.to_f
- @body[:quantity] = quantity.to_f
- @body[:sum] = (@body[:price] * @body[:quantity]).to_f.round(2)
- @body[:tax] = @config.default_tax
+ @config = config || Atol.config
+ @name = name
+ @price = price.to_f
+ @quantity = quantity.to_f
end
def to_h
- @body.clone
+ body.clone
+ end
+
+ def to_json
+ body.to_json
+ end
+
+ private
+
+ def body
+ @body ||= {
+ name: @name,
+ price: @price,
+ quantity: @quantity,
+ sum: (@price * @quantity).round(2),
+ tax: @config.default_tax
+ }
end
end
end
end
end