rvista 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,13 @@
1
- v0.6.3 (13th November 2009)
1
+ v0.6.4 (18th November 2009)
2
+ - RVista::POA, RVista::Invoice
2
3
  - Use correct vista date format (dd-mm-yy)
3
4
  - return dates as ruby date objects
4
5
 
6
+ v0.6.3 (13th November 2009)
7
+ - RVista::PO
8
+ - Use correct vista date format (dd-mm-yy)
9
+ - return dates as ruby date objects
10
+
5
11
  v0.6.2 (19th August 2009)
6
12
  - don't barf on input files with quotes in them
7
13
 
data/Rakefile CHANGED
@@ -5,10 +5,9 @@ require 'rake/testtask'
5
5
  require "rake/gempackagetask"
6
6
  require "rubygems"
7
7
 
8
- PKG_VERSION = "0.6.3"
8
+ PKG_VERSION = "0.6.4"
9
9
  PKG_NAME = "rvista"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
- RUBY_FORGE_PROJECT = "rbook"
12
11
 
13
12
  CLEAN.include "**/.*.sw*"
14
13
 
@@ -54,7 +53,6 @@ spec = Gem::Specification.new do |spec|
54
53
  '--main' << 'README' << '-q'
55
54
  spec.author = "James Healy"
56
55
  spec.email = "jimmy@deefa.com"
57
- spec.rubyforge_project = RUBY_FORGE_PROJECT
58
56
  spec.add_dependency('chronic')
59
57
  spec.description = <<END_DESC
60
58
  rvista is a small library for reading Vista HDS order files.
@@ -3,16 +3,17 @@
3
3
  module RVista
4
4
 
5
5
  # Represents a single Vista Invoice
6
- class Invoice
6
+ class Invoice < Message
7
7
 
8
8
  attr_accessor :sender_id, :receiver_id, :doc_type, :description
9
- attr_accessor :doc_number, :doc_date, :delivery_location, :currency
9
+ attr_accessor :doc_number, :delivery_location, :currency
10
10
  attr_accessor :items
11
11
  attr_accessor :total_value, :total_qty, :total_gst
12
12
 
13
13
  # creates a new RVista::Invoice object
14
14
  def initialize
15
15
  @items = []
16
+ @doc_date = nil
16
17
  end
17
18
 
18
19
  # reads a vista invoice file into memory. input should be a string
@@ -30,6 +31,14 @@ module RVista
30
31
  return self.build_message(data)
31
32
  end
32
33
 
34
+ def doc_date
35
+ vista_string_to_date(@doc_date)
36
+ end
37
+
38
+ def doc_date=(val)
39
+ @doc_date = process_date(val)
40
+ end
41
+
33
42
  # print a string representation of this order that meets the spec
34
43
  def to_s
35
44
  # message header
@@ -40,7 +49,7 @@ module RVista
40
49
  msg << "#{doc_type.to_s[0,4]},"
41
50
  msg << "#{description.to_s[0,30]},"
42
51
  msg << "#{doc_number.to_s[0,8]},"
43
- msg << "#{doc_date.to_s[0,8]},"
52
+ msg << "#{@doc_date},"
44
53
  msg << "#{delivery_location.to_s[0,10]},"
45
54
  msg << "#{currency.to_s[0,4]}\n"
46
55
 
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ module RVista
4
+
5
+ # Parent class of all 3 vista HDS message types
6
+ class Message #nodoc
7
+
8
+ private
9
+
10
+ # convert a vista date format
11
+ def vista_string_to_date(str)
12
+ if str.nil? || str.to_s[0,2] == "00" || str.to_s.size != 8
13
+ nil
14
+ else
15
+ year = "20#{str[6,2]}"
16
+ month = str[3,2]
17
+ day = str[0,2]
18
+ Chronic.parse("#{year}-#{month}-#{day}")
19
+ end
20
+ end
21
+
22
+ def process_date(value)
23
+ if value.respond_to?(:strftime)
24
+ value.strftime("%d-%m-%y")
25
+ else
26
+ value
27
+ end
28
+ end
29
+ end
30
+
31
+ end
data/lib/rvista/po.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module RVista
4
4
 
5
5
  # Represents a single Vista message (purchase order).
6
- class PO
6
+ class PO < Message
7
7
 
8
8
  attr_accessor :sender_id, :receiver_id, :internal_control_number, :po_number
9
9
  attr_accessor :po_subset_code, :purpose_code, :purpose_desc
@@ -144,32 +144,5 @@ module RVista
144
144
  # return the results
145
145
  return msg
146
146
  end
147
-
148
- def vista_string_to_date(str)
149
- if str.nil? || str.to_s[0,2] == "00" || str.to_s.size != 8
150
- nil
151
- else
152
- year = "20#{str[6,2]}"
153
- month = str[3,2]
154
- day = str[0,2]
155
- Chronic.parse("#{year}-#{month}-#{day}")
156
- end
157
- end
158
-
159
- def process_date(value)
160
- if value.respond_to?(:strftime)
161
- value.strftime("%d-%m-%y")
162
- else
163
- value
164
- end
165
- end
166
- end
167
-
168
- class Message < PO
169
-
170
- def initialize
171
- $stderr.puts "WARNING: RVista::Message is a deprecated class. Please use RVista::PO instead."
172
- super
173
- end
174
147
  end
175
148
  end
data/lib/rvista/poa.rb CHANGED
@@ -3,16 +3,18 @@
3
3
  module RVista
4
4
 
5
5
  # Represents a single Vista Purchase Order Ack (POA).
6
- class POA
6
+ class POA < Message
7
7
 
8
- attr_accessor :sender_id, :receiver_id, :po_number, :date
9
- attr_accessor :supply_after, :supply_before, :delivery_location
10
- attr_accessor :delivery_location_name
8
+ attr_accessor :sender_id, :receiver_id, :po_number
9
+ attr_accessor :delivery_location, :delivery_location_name
11
10
  attr_accessor :items
12
11
 
13
12
  # creates a new RVista::POA object
14
13
  def initialize
15
14
  @items = []
15
+ @date = nil
16
+ @supply_before = nil
17
+ @supply_after = nil
16
18
  end
17
19
 
18
20
  # reads a vista poa file into memory. input should be a string
@@ -30,6 +32,30 @@ module RVista
30
32
  return self.build_message(data)
31
33
  end
32
34
 
35
+ def date
36
+ vista_string_to_date(@date)
37
+ end
38
+
39
+ def date=(val)
40
+ @date = process_date(val)
41
+ end
42
+
43
+ def supply_after
44
+ vista_string_to_date(@supply_after)
45
+ end
46
+
47
+ def supply_after=(val)
48
+ @supply_after = process_date(val)
49
+ end
50
+
51
+ def supply_before
52
+ vista_string_to_date(@supply_before)
53
+ end
54
+
55
+ def supply_before=(val)
56
+ @supply_before = process_date(val)
57
+ end
58
+
33
59
  # print a string representation of this order that meets the spec
34
60
  def to_s
35
61
  # message header
@@ -42,10 +68,10 @@ module RVista
42
68
  msg << ","
43
69
  msg << ","
44
70
  msg << "#{po_number},"
45
- msg << "#{date},"
71
+ msg << "#{@date},"
46
72
  msg << ","
47
- msg << "#{supply_after},"
48
- msg << "#{supply_before},"
73
+ msg << "#{@supply_after},"
74
+ msg << "#{@supply_before},"
49
75
  msg << "SP,"
50
76
  msg << "#{delivery_location},"
51
77
  msg << "#{delivery_location_name}\n"
data/lib/rvista.rb CHANGED
@@ -22,6 +22,7 @@ end
22
22
 
23
23
 
24
24
  require File.dirname(__FILE__) + '/rvista/errors'
25
+ require File.dirname(__FILE__) + '/rvista/message'
25
26
  require File.dirname(__FILE__) + '/rvista/invoice'
26
27
  require File.dirname(__FILE__) + '/rvista/invoice_line_item'
27
28
  require File.dirname(__FILE__) + '/rvista/po'
@@ -1,4 +1,4 @@
1
- H,1111111,2222222,IN,Invoice,5678,071011,1111111,
1
+ H,1111111,2222222,IN,Invoice,5678,11-10-07,1111111,
2
2
  D,1,1234,EN,9781857230765,Eye of the World,2,EA,500,4000,450,Y,1000,600,1000,100,F
3
3
  D,2,1234,EN,9780744590104,Eye of the Wolf,3,EA,500,4000,450,Y,1500,900,1000,100,F
4
4
  S,2,2200,5,200
@@ -1,4 +1,4 @@
1
- H,1111111,2222222,,,,,1234,060915,,071010,071030,SP,1111111,Some Store
1
+ H,1111111,2222222,,,,,1234,15-09-06,,10-10-07,30-10-07,SP,1111111,Some Store
2
2
  D,1,0701180358,,DIGGING TO AMERICA,10.00,1,0,10.00,,1111111,Some Store,,1,01,1,11.00,40.00,20071015,
3
3
  D,2,071267344X,,THE LAST ENEMY,15.00,1,0,10.00,,1111111,Some Store,,7,02,5,16.50,50.00,20071015,
4
4
  S,2,6
@@ -69,7 +69,7 @@ class InvoiceTest < Test::Unit::TestCase
69
69
  assert_equal msg.doc_type, "IN"
70
70
  assert_equal msg.description, "Invoice"
71
71
  assert_equal msg.doc_number, "5678"
72
- assert_equal msg.doc_date, "071011"
72
+ assert_equal msg.doc_date, Chronic.parse("2007-10-11")
73
73
  assert_equal msg.delivery_location, "1111111"
74
74
  assert_equal msg.currency, nil
75
75
  end
@@ -66,9 +66,9 @@ class POATest < Test::Unit::TestCase
66
66
  assert_equal msg.sender_id, "1111111"
67
67
  assert_equal msg.receiver_id, "2222222"
68
68
  assert_equal msg.po_number, "1234"
69
- assert_equal msg.date, "060915"
70
- assert_equal msg.supply_after, "071010"
71
- assert_equal msg.supply_before, "071030"
69
+ assert_equal msg.date, Chronic.parse("2006-09-15")
70
+ assert_equal msg.supply_after, Chronic.parse("2007-10-10")
71
+ assert_equal msg.supply_before, Chronic.parse("2007-10-30")
72
72
  assert_equal msg.delivery_location, "1111111"
73
73
  assert_equal msg.delivery_location_name, "Some Store"
74
74
  end
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.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 +11:00
12
+ date: 2009-11-18 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,6 +40,7 @@ files:
40
40
  - lib/rvista/poa_line_item.rb
41
41
  - lib/rvista/po.rb
42
42
  - lib/rvista/invoice_line_item.rb
43
+ - lib/rvista/message.rb
43
44
  - lib/rvista/poa.rb
44
45
  - lib/rvista/po_line_item.rb
45
46
  - test/data/poa/invalid_line.txt
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  version:
96
97
  requirements: []
97
98
 
98
- rubyforge_project: rbook
99
+ rubyforge_project:
99
100
  rubygems_version: 1.3.5
100
101
  signing_key:
101
102
  specification_version: 3