Class: MusicTodayApiWrapper::Resources::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(street, state, city, postal_code, country = 'US', street_second_line = '', shipping_options = [], selected_shipping = nil) ⇒ Address

rubocop:disable ParameterLists



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/resources/address.rb', line 16

def initialize(street, state, city, postal_code, country = 'US',
  street_second_line = '', shipping_options = [],
  selected_shipping = nil)
  @street = street
  @state = state
  @street_second_line = street_second_line
  @city = city
  @postal_code = postal_code
  @country = country
  @shipping_options = shipping_options
  @selected_shipping = selected_shipping
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/resources/address.rb', line 7

def city
  @city
end

#countryObject

Returns the value of attribute country.



7
8
9
# File 'lib/resources/address.rb', line 7

def country
  @country
end

#postal_codeObject

Returns the value of attribute postal_code.



7
8
9
# File 'lib/resources/address.rb', line 7

def postal_code
  @postal_code
end

#selected_shippingObject

Returns the value of attribute selected_shipping.



7
8
9
# File 'lib/resources/address.rb', line 7

def selected_shipping
  @selected_shipping
end

#shipping_optionsObject

Returns the value of attribute shipping_options.



7
8
9
# File 'lib/resources/address.rb', line 7

def shipping_options
  @shipping_options
end

#streetObject

Returns the value of attribute street.



7
8
9
# File 'lib/resources/address.rb', line 7

def street
  @street
end

#street_second_lineObject

Returns the value of attribute street_second_line.



7
8
9
# File 'lib/resources/address.rb', line 7

def street_second_line
  @street_second_line
end

Class Method Details

.from_destinations(destinations) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/resources/address.rb', line 47

def self.from_destinations(destinations)
  destinations.map do |destination|
    customer = destination.customer
    address = new(customer.street,
                  customer.state,
                  customer.city,
                  customer.zip_code)
    address.selected_shipping = destination.shipping_option
    address
  end
end

.from_hash(address_hash) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/resources/address.rb', line 29

def self.from_hash(address_hash)
  Address.new(address_hash['street'],
              address_hash['city'],
              address_hash['postalCode'],
              address_hash['country'],
              address_hash['street2'])
end

Instance Method Details

#as_hashObject



37
38
39
40
41
42
43
44
45
# File 'lib/resources/address.rb', line 37

def as_hash
  { street: @street,
    street2: @street_second_line,
    state: @state,
    city: @city,
    postalCode: @postal_code,
    country: @country,
    shippingOptionType: @selected_shipping }.compact
end