Class: Docdata::Shopper

Inherits:
Object
  • Object
show all
Defined in:
lib/docdata/shopper.rb

Overview

Object representing a "Shopper"

Examples:

Shopper.new({
  :first_name => "Jack",
  :last_name => "Sixpack"
  :id => "MC123"
})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Shopper

Initializer to transform a +Hash+ into an Shopper object

Parameters:

  • args (Hash) (defaults to: nil)


63
64
65
66
67
68
69
70
# 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

Instance Attribute Details

#cityObject

Returns the value of attribute city.



51
52
53
# File 'lib/docdata/shopper.rb', line 51

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



53
54
55
# File 'lib/docdata/shopper.rb', line 53

def country_code
  @country_code
end

#emailObject

Returns the value of attribute email.



52
53
54
# File 'lib/docdata/shopper.rb', line 52

def email
  @email
end

#errorsArray

Returns Errors.

Returns:

  • (Array)

    Errors



43
44
45
# File 'lib/docdata/shopper.rb', line 43

def errors
  @errors
end

#first_nameObject

Returns the value of attribute first_name.



45
46
47
# File 'lib/docdata/shopper.rb', line 45

def first_name
  @first_name
end

#genderObject

Returns the value of attribute gender.



47
48
49
# File 'lib/docdata/shopper.rb', line 47

def gender
  @gender
end

#house_numberObject

Returns the value of attribute house_number.



49
50
51
# File 'lib/docdata/shopper.rb', line 49

def house_number
  @house_number
end

#idObject

Returns the value of attribute id.



44
45
46
# File 'lib/docdata/shopper.rb', line 44

def id
  @id
end

#language_codeObject

Returns the value of attribute language_code.



54
55
56
# File 'lib/docdata/shopper.rb', line 54

def language_code
  @language_code
end

#last_nameObject

Returns the value of attribute last_name.



46
47
48
# File 'lib/docdata/shopper.rb', line 46

def last_name
  @last_name
end

#postal_codeObject

Returns the value of attribute postal_code.



50
51
52
# File 'lib/docdata/shopper.rb', line 50

def postal_code
  @postal_code
end

#streetObject

Returns the value of attribute street.



48
49
50
# File 'lib/docdata/shopper.rb', line 48

def street
  @street
end

Class Method Details

.create_valid_shopperObject

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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 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         = "[email protected]"
  shopper.street        = "Main street"
  shopper.house_number  = "123"
  shopper.postal_code   = "1122AB"
  shopper.city          = "Test City"
  return shopper
end

Instance Method Details

#nameObject



72
73
74
# File 'lib/docdata/shopper.rb', line 72

def name
  "#{first_name} #{last_name}"
end

#set_default_valuesObject



83
84
85
86
87
88
89
90
91
92
93
94
# 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         = "[email protected]"
end

#valid?Boolean

Returns true if this instanciated object is valid

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/docdata/shopper.rb', line 77

def valid?
  validator = ShopperValidator.new
  validator.valid?(self)
end