class Docdata::Shopper
Object
representing a “Shopper”
@example
Shopper.new({ :first_name => "Jack", :last_name => "Sixpack" :id => "MC123" })
@param format [String] The shopper ID @param format [String] Shopper
first name @param format [String] Shopper
last name @param format [String] Gender [‘M’,‘F’] @param format [String] Shopper
street address @param format [String] Shopper
house number @param format [String] Shopper
postal code @param format [String] Shopper
city @param format [String] Shopper
email @param format [String] ISO country code (us, nl, de, uk) @param format [String] ISO language code (en, nl, de)
Attributes
@return [Array] Errors
Public Class Methods
This method will instanciate and return a new Shopper
object with all the required properties set. Mostly for testing purpose, but maybe usefull in other scenarios as well.
# File lib/docdata/shopper.rb, line 99 def self.create_valid_shopper shopper = self.new shopper.id = "789" shopper.first_name = "John" shopper.last_name = "Doe" shopper.country_code = "NL" shopper.language_code = "nl" shopper.email = "test@example.org" shopper.street = "Main street" shopper.house_number = "123" shopper.postal_code = "1122AB" shopper.city = "Test City" return shopper end
Initializer to transform a Hash
into an Shopper
object
@param [Hash] args
# File lib/docdata/shopper.rb, line 63 def initialize(args=nil) self.set_default_values return if args.nil? args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end
Public Instance Methods
# File lib/docdata/shopper.rb, line 72 def name "#{first_name} #{last_name}" end
# File lib/docdata/shopper.rb, line 83 def set_default_values @first_name = "First Name" @last_name = "Last Name" @street = "Main Street" @house_number = "123" @postal_code = "2244" @city = "City" @country_code = "NL" @language_code = "nl" @gender = "M" @email = "random@example.com" end
Returns true if this instanciated object is valid
# File lib/docdata/shopper.rb, line 77 def valid? validator = ShopperValidator.new validator.valid?(self) end