milkfarm-onix 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.8.11 (27 May 2011)
2
+ - Add Territory, CountryExcluded, TerritoryExcluded to Price composite
3
+ - Add CountryCode to Price composite
4
+
1
5
  v0.8.10 (25 May 2011)
2
6
  - Add DiscountCoded to Price composite
3
7
  - Add DiscountPercent to Price composite
@@ -9,11 +9,31 @@ module ONIX
9
9
  raise ArgumentError, "Must specify code list number as ':list => Integer'"
10
10
  end
11
11
  define_method("#{name}=") do |value|
12
- if value.nil? || ONIX::Lists.list(options[:list]).keys.include?(value)
13
- self.instance_variable_set("@#{name}", value)
12
+ # Value can be Array, String or Fixnum
13
+ # To iterate over all classes, convert all to Array
14
+ # NB: Some entities (j303, j304, j305) can be space-separated string of values
15
+ values = case value.class.to_s
16
+ when 'Array'
17
+ value
18
+ when 'String'
19
+ value.split(/\s+/)
14
20
  else
15
- raise ArgumentError, "Invalid #{("_" + name.to_s).downcase.gsub!(/_(.)/) { $1.upcase }} '#{value}' -- Refer to ONIX Code List #{options[:list]}"
21
+ [value]
16
22
  end
23
+ values.each do |value|
24
+ unless value.nil? || ONIX::Lists.list(options[:list]).keys.include?(value)
25
+ raise ArgumentError, "Invalid #{("_" + name.to_s).downcase.gsub!(/_(.)/) { $1.upcase }} '#{value}' -- Refer to ONIX Code List #{options[:list]}"
26
+ end
27
+ end
28
+ # :as option determines how value is stored in instance variable
29
+ values = if options[:as] == Array || options[:as] == []
30
+ values
31
+ elsif options[:as] == String
32
+ values.join(" ")
33
+ else
34
+ values.first
35
+ end
36
+ self.instance_variable_set("@#{name}", values)
17
37
  end
18
38
  end
19
39
 
@@ -4,6 +4,7 @@ module ONIX
4
4
  class Price
5
5
  include ROXML
6
6
  include ONIX::DiscountCodeds
7
+ extend ONIX::ListWriter
7
8
 
8
9
  xml_name "Price"
9
10
 
@@ -19,11 +20,20 @@ module ONIX
19
20
  xml_accessor :price_status, :from => "PriceStatus", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
20
21
  xml_accessor :price_amount, :from => "PriceAmount", :as => BigDecimal, :to_xml => ONIX::Formatters.decimal
21
22
  xml_accessor :currency_code, :from => "CurrencyCode"
23
+ xml_reader :country_codes, :from => "CountryCode", :as => []
24
+ list_writer :country_codes, :list => 91, :as => []
25
+ xml_reader :territory, :from => "Territory"
26
+ list_writer :territory, :list => 49, :as => String
27
+ xml_reader :country_excluded, :from => "CountryExcluded"
28
+ list_writer :country_excluded, :list => 91, :as => String
29
+ xml_reader :territory_excluded, :from => "TerritoryExcluded"
30
+ list_writer :territory_excluded, :list => 49, :as => String
22
31
  xml_accessor :price_effective_from, :from => "PriceEffectiveFrom", :to_xml => ONIX::Formatters.yyyymmdd
23
32
  xml_accessor :price_effective_until, :from => "PriceEffectiveUntil", :to_xml => ONIX::Formatters.yyyymmdd
24
33
 
25
34
  def initialize(options = {})
26
35
  initialize_discount_codeds(options) # @discount_codeds array
36
+ @country_codes = []
27
37
  end
28
38
  end
29
39
  end
@@ -1,3 +1,3 @@
1
1
  module ONIX
2
- VERSION = "0.8.10"
2
+ VERSION = "0.8.11"
3
3
  end
@@ -24,6 +24,11 @@ describe ONIX::Price do
24
24
  p.price_amount.should eql(BigDecimal.new("7.5"))
25
25
  p.price_effective_from.should eql("19990101")
26
26
  p.price_effective_until.should eql("20001231")
27
+ p.country_codes.should be_a(Array)
28
+ p.country_codes[0].should eql("US")
29
+ p.territory.should eql("WORLD")
30
+ p.country_excluded.should eql("AD AE")
31
+ p.territory_excluded.should eql("AU-CT AU-NS")
27
32
  end
28
33
 
29
34
  it "should provide read access to discount_codeds" do
@@ -55,6 +60,19 @@ describe ONIX::Price do
55
60
  p.price_amount = BigDecimal.new("7.5")
56
61
  p.to_xml.to_s.include?("<PriceAmount>7.5</PriceAmount>").should be_true
57
62
 
63
+ p.country_codes = ["AD", "AE"]
64
+ p.to_xml.to_s.include?("<CountryCode>AD</CountryCode>").should be_true
65
+ p.to_xml.to_s.include?("<CountryCode>AE</CountryCode>").should be_true
66
+
67
+ p.territory = "AU-CT AU-NS"
68
+ p.to_xml.to_s.include?("<Territory>AU-CT AU-NS</Territory>").should be_true
69
+
70
+ p.country_excluded = "AD AE"
71
+ p.to_xml.to_s.include?("<CountryExcluded>AD AE</CountryExcluded>").should be_true
72
+
73
+ p.territory_excluded = "AU-CT AU-NS"
74
+ p.to_xml.to_s.include?("<TerritoryExcluded>AU-CT AU-NS</TerritoryExcluded>").should be_true
75
+
58
76
  p.price_effective_from = Date.civil(1999,1,1)
59
77
  p.to_xml.to_s.include?("<PriceEffectiveFrom>19990101</PriceEffectiveFrom>").should be_true
60
78
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkfarm-onix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 10
10
- version: 0.8.10
9
+ - 11
10
+ version: 0.8.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Healy
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-25 00:00:00 -07:00
19
+ date: 2011-05-27 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency