Class: Docdata::Shopper
- Inherits:
-
Object
- Object
- Docdata::Shopper
- Defined in:
- lib/docdata/shopper.rb
Overview
Object representing a "Shopper"
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#email ⇒ Object
Returns the value of attribute email.
-
#errors ⇒ Array
Errors.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#house_number ⇒ Object
Returns the value of attribute house_number.
-
#id ⇒ Object
Returns the value of attribute id.
-
#language_code ⇒ Object
Returns the value of attribute language_code.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#street ⇒ Object
Returns the value of attribute street.
Class Method Summary collapse
-
.create_valid_shopper ⇒ Object
This method will instanciate and return a new Shopper object with all the required properties set.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ Shopper
constructor
Initializer to transform a +Hash+ into an Shopper object.
- #name ⇒ Object
- #set_default_values ⇒ Object
-
#valid? ⇒ Boolean
Returns true if this instanciated object is valid.
Constructor Details
#initialize(args = nil) ⇒ Shopper
Initializer to transform a +Hash+ into an Shopper object
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
#city ⇒ Object
Returns the value of attribute city.
51 52 53 |
# File 'lib/docdata/shopper.rb', line 51 def city @city end |
#country_code ⇒ Object
Returns the value of attribute country_code.
53 54 55 |
# File 'lib/docdata/shopper.rb', line 53 def country_code @country_code end |
#email ⇒ Object
Returns the value of attribute email.
52 53 54 |
# File 'lib/docdata/shopper.rb', line 52 def email @email end |
#errors ⇒ Array
Returns Errors.
43 44 45 |
# File 'lib/docdata/shopper.rb', line 43 def errors @errors end |
#first_name ⇒ Object
Returns the value of attribute first_name.
45 46 47 |
# File 'lib/docdata/shopper.rb', line 45 def first_name @first_name end |
#gender ⇒ Object
Returns the value of attribute gender.
47 48 49 |
# File 'lib/docdata/shopper.rb', line 47 def gender @gender end |
#house_number ⇒ Object
Returns the value of attribute house_number.
49 50 51 |
# File 'lib/docdata/shopper.rb', line 49 def house_number @house_number end |
#id ⇒ Object
Returns the value of attribute id.
44 45 46 |
# File 'lib/docdata/shopper.rb', line 44 def id @id end |
#language_code ⇒ Object
Returns the value of attribute language_code.
54 55 56 |
# File 'lib/docdata/shopper.rb', line 54 def language_code @language_code end |
#last_name ⇒ Object
Returns the value of attribute last_name.
46 47 48 |
# File 'lib/docdata/shopper.rb', line 46 def last_name @last_name end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
50 51 52 |
# File 'lib/docdata/shopper.rb', line 50 def postal_code @postal_code end |
#street ⇒ Object
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_shopper ⇒ Object
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
#name ⇒ Object
72 73 74 |
# File 'lib/docdata/shopper.rb', line 72 def name "#{first_name} #{last_name}" end |
#set_default_values ⇒ Object
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
77 78 79 80 |
# File 'lib/docdata/shopper.rb', line 77 def valid? validator = ShopperValidator.new validator.valid?(self) end |