Class: RVista::PO

Inherits:
Message show all
Defined in:
lib/rvista/po.rb

Overview

Represents a single Vista message (purchase order).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePO

creates a new RVista::PO object



16
17
18
19
20
21
22
# File 'lib/rvista/po.rb', line 16

def initialize
  @items = []
  @date = nil
  @supply_before = nil
  @supply_after = nil
  @advertised_date = nil
end

Instance Attribute Details

#buying_locationObject

Returns the value of attribute buying_location.



10
11
12
# File 'lib/rvista/po.rb', line 10

def buying_location
  @buying_location
end

#buying_location_nameObject

Returns the value of attribute buying_location_name.



11
12
13
# File 'lib/rvista/po.rb', line 11

def buying_location_name
  @buying_location_name
end

#delivery_locationObject

Returns the value of attribute delivery_location.



11
12
13
# File 'lib/rvista/po.rb', line 11

def delivery_location
  @delivery_location
end

#delivery_location_nameObject

Returns the value of attribute delivery_location_name.



12
13
14
# File 'lib/rvista/po.rb', line 12

def delivery_location_name
  @delivery_location_name
end

#departmentObject

Returns the value of attribute department.



10
11
12
# File 'lib/rvista/po.rb', line 10

def department
  @department
end

#internal_control_numberObject

Returns the value of attribute internal_control_number.



8
9
10
# File 'lib/rvista/po.rb', line 8

def internal_control_number
  @internal_control_number
end

#itemsObject

Returns the value of attribute items.



13
14
15
# File 'lib/rvista/po.rb', line 13

def items
  @items
end

#label_codeObject

Returns the value of attribute label_code.



12
13
14
# File 'lib/rvista/po.rb', line 12

def label_code
  @label_code
end

#myer_codeObject

Returns the value of attribute myer_code.



10
11
12
# File 'lib/rvista/po.rb', line 10

def myer_code
  @myer_code
end

#po_numberObject

Returns the value of attribute po_number.



8
9
10
# File 'lib/rvista/po.rb', line 8

def po_number
  @po_number
end

#po_subset_codeObject

Returns the value of attribute po_subset_code.



9
10
11
# File 'lib/rvista/po.rb', line 9

def po_subset_code
  @po_subset_code
end

#purpose_codeObject

Returns the value of attribute purpose_code.



9
10
11
# File 'lib/rvista/po.rb', line 9

def purpose_code
  @purpose_code
end

#purpose_descObject

Returns the value of attribute purpose_desc.



9
10
11
# File 'lib/rvista/po.rb', line 9

def purpose_desc
  @purpose_desc
end

#receiver_idObject

Returns the value of attribute receiver_id.



8
9
10
# File 'lib/rvista/po.rb', line 8

def receiver_id
  @receiver_id
end

#sender_idObject

Returns the value of attribute sender_id.



8
9
10
# File 'lib/rvista/po.rb', line 8

def sender_id
  @sender_id
end

#supplier_refObject

Returns the value of attribute supplier_ref.



10
11
12
# File 'lib/rvista/po.rb', line 10

def supplier_ref
  @supplier_ref
end

Class Method Details

.load_from_file(input) ⇒ Object

reads a vista text file into memory. input should be a string that specifies the file path

Raises:



26
27
28
29
30
# File 'lib/rvista/po.rb', line 26

def self.load_from_file(input)
  raise InvalidFileError, 'Invalid file' unless File.exist?(input)
  data = CSV.read(input, :quote_char => "`")
  return self.build_message(data)
end

.load_from_string(input) ⇒ Object

creates a RVista::Message object from a string. Input should be a complete vista file as a string



34
35
36
37
# File 'lib/rvista/po.rb', line 34

def self.load_from_string(input)
  data = CSV.parse(input, :quote_char => "`")
  return self.build_message(data)
end

Instance Method Details

#advertised_dateObject



63
64
65
# File 'lib/rvista/po.rb', line 63

def advertised_date
  vista_string_to_date(@advertised_date)
end

#advertised_date=(val) ⇒ Object



67
68
69
# File 'lib/rvista/po.rb', line 67

def advertised_date=(val)
  @advertised_date = process_date(val)
end

#dateObject



39
40
41
# File 'lib/rvista/po.rb', line 39

def date
  vista_string_to_date(@date)
end

#date=(val) ⇒ Object



43
44
45
# File 'lib/rvista/po.rb', line 43

def date=(val)
  @date = process_date(val)
end

#supply_afterObject



47
48
49
# File 'lib/rvista/po.rb', line 47

def supply_after
  vista_string_to_date(@supply_after)
end

#supply_after=(val) ⇒ Object



51
52
53
# File 'lib/rvista/po.rb', line 51

def supply_after=(val)
  @supply_after = process_date(val)
end

#supply_beforeObject



55
56
57
# File 'lib/rvista/po.rb', line 55

def supply_before
  vista_string_to_date(@supply_before)
end

#supply_before=(val) ⇒ Object



59
60
61
# File 'lib/rvista/po.rb', line 59

def supply_before=(val)
  @supply_before = process_date(val)
end

#to_sObject

print a string representation of this order that meets the spec



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rvista/po.rb', line 72

def to_s
  # message header
  msg = ""
  msg << "H,"
  msg << "#{sender_id},"
  msg << "#{receiver_id},"
  msg << "#{internal_control_number},"
  msg << "#{po_number},"
  msg << "#{po_subset_code},"
  msg << "#{purpose_code},"
  msg << "#{purpose_desc},"
  msg << "#{@date},"
  msg << "#{myer_code},"
  msg << "#{@supply_after},"
  msg << "#{@supply_before},"
  msg << "#{@advertised_date},"
  msg << "#{department},"
  msg << "#{supplier_ref},"
  msg << "#{buying_location},"
  msg << "#{buying_location_name},"
  msg << "#{delivery_location},"
  msg << "#{delivery_location_name},"
  msg << "#{label_code}\n"
  
  # message line items
  @items.each { |item| msg << item.to_s << "\n"}

  # message summary
  msg << "S,#{@items.size.to_s},,\n"

  return msg
end