rvista 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,10 @@
1
+ v0.6.5 (16th January 2010)
2
+ - RVista::POA: handle invalid looking numbers sanely
3
+
1
4
  v0.6.4 (18th November 2009)
2
5
  - RVista::POA, RVista::Invoice
3
- - Use correct vista date format (dd-mm-yy)
4
- - return dates as ruby date objects
6
+ - Use correct vista date format (dd-mm-yy)
7
+ - return dates as ruby date objects
5
8
 
6
9
  v0.6.3 (13th November 2009)
7
10
  - RVista::PO
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require "rake/gempackagetask"
6
6
  require "rubygems"
7
7
 
8
- PKG_VERSION = "0.6.4"
8
+ PKG_VERSION = "0.6.5"
9
9
  PKG_NAME = "rvista"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
11
 
@@ -53,6 +53,7 @@ spec = Gem::Specification.new do |spec|
53
53
  '--main' << 'README' << '-q'
54
54
  spec.author = "James Healy"
55
55
  spec.email = "jimmy@deefa.com"
56
+ spec.add_dependency('andand')
56
57
  spec.add_dependency('chronic')
57
58
  spec.description = <<END_DESC
58
59
  rvista is a small library for reading Vista HDS order files.
@@ -34,7 +34,7 @@ module RVista
34
34
  item.demand_qty = data[15].to_i
35
35
  item.rrp = BigDecimal.new(data[16]) unless data[16].nil?
36
36
  item.discount_percent = BigDecimal.new(data[17]) unless data[17].nil?
37
- item.availability_date = data[18] # TODO: convert this to a Date?
37
+ item.availability_date = data[18] # TODO: convert this to a Date?
38
38
  item.text = data[19]
39
39
 
40
40
  return item
@@ -75,21 +75,22 @@ module RVista
75
75
  "UNKNOWN"
76
76
  end
77
77
  end
78
-
78
+
79
79
  # output a string that represents this line item that meets the vista spec
80
80
  def to_s
81
+ nil_numeric_values
82
+ normalise_numeric_values
83
+
81
84
  msg = ""
82
- msg << "D,"
85
+ msg << "D,"
83
86
  msg << "#{line_num},"
84
87
  msg << "#{ean},"
85
88
  msg << ","
86
89
  msg << "#{description},"
87
- msg << sprintf("%.2f", nett_unit_price) unless nett_unit_price.nil?
88
- msg << ","
90
+ msg << "#{formatted_nett_unit_price},"
89
91
  msg << "1,"
90
92
  msg << "#{qty_inners},"
91
- msg << sprintf("%.2f", tax_rate) unless tax_rate.nil?
92
- msg << ","
93
+ msg << "#{formatted_tax_rate},"
93
94
  msg << ","
94
95
  msg << "#{buying_location},"
95
96
  msg << "#{buying_location_name},"
@@ -97,13 +98,47 @@ module RVista
97
98
  msg << "#{delivered_qty},"
98
99
  msg << "#{status_code},"
99
100
  msg << "#{demand_qty},"
100
- msg << sprintf("%.2f", rrp) unless rrp.nil?
101
- msg << ","
102
- msg << sprintf("%.2f", discount_percent) unless discount_percent.nil?
103
- msg << ","
101
+ msg << "#{formatted_rrp},"
102
+ msg << "#{formatted_discount_percent},"
104
103
  msg << "#{availability_date},"
105
104
  msg << "#{text}"
106
105
  return msg
107
106
  end
107
+
108
+ private
109
+
110
+ # ensure all decimal attributes are BigDecimals
111
+ #
112
+ def nil_numeric_values
113
+ self.nett_unit_price = nil if self.nett_unit_price.to_s.size == 0
114
+ self.tax_rate = nil if self.tax_rate.to_s.size == 0
115
+ self.rrp = nil if self.rrp.to_s.size == 0
116
+ self.discount_percent = nil if self.discount_percent.to_s.size == 0
117
+ end
118
+
119
+ # set empty numerics to nil
120
+ #
121
+ def normalise_numeric_values
122
+ self.nett_unit_price = BigDecimal.new(self.nett_unit_price.to_s) unless self.nett_unit_price.nil?
123
+ self.tax_rate = BigDecimal.new(self.tax_rate.to_s) unless self.tax_rate.nil?
124
+ self.rrp = BigDecimal.new(self.rrp.to_s) unless self.rrp.nil?
125
+ self.discount_percent = BigDecimal.new(self.discount_percent.to_s) unless self.discount_percent.nil?
126
+ end
127
+
128
+ def formatted_nett_unit_price
129
+ self.nett_unit_price.nil? ? "" : "%.2f" % self.nett_unit_price
130
+ end
131
+
132
+ def formatted_tax_rate
133
+ self.tax_rate.nil? ? "" : "%.2f" % self.tax_rate
134
+ end
135
+
136
+ def formatted_rrp
137
+ self.rrp.nil? ? "" : "%.2f" % self.rrp
138
+ end
139
+
140
+ def formatted_discount_percent
141
+ self.discount_percent.nil? ? "" : "%.2f" % self.discount_percent
142
+ end
108
143
  end
109
144
  end
data/lib/rvista.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'andand'
3
4
  require 'chronic'
4
5
 
5
6
  # faster csv is distributed with ruby 1.9 as "CSV", so we only
@@ -74,6 +74,18 @@ class POALineItemTest < Test::Unit::TestCase
74
74
  assert_equal 20, arr.size
75
75
  end
76
76
 
77
+ def test_to_s_with_invalid_decimals
78
+ item = RVista::POALineItem.load_from_array(@row)
79
+ item.nett_unit_price = ""
80
+ item.rrp = ""
81
+ item.tax_rate = ""
82
+ item.discount_percent = ""
83
+
84
+ str = item.to_s
85
+ arr = FasterCSV.parse(str).first
86
+ assert_equal 20, arr.size
87
+ end
88
+
77
89
  end
78
90
 
79
91
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 +11:00
12
+ date: 2010-01-16 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: andand
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: chronic
17
27
  type: :runtime