class XeroRuby::Accounting::Address

Constants

POBOX
STREET

Attributes

address_line1[RW]

max length = 500

address_line2[RW]

max length = 500

address_line3[RW]

max length = 500

address_line4[RW]

max length = 500

address_type[RW]

define the type of address

attention_to[RW]

max length = 255

city[RW]

max length = 255

country[RW]

max length = 50, [A-Z], [a-z] only

postal_code[RW]

max length = 50

region[RW]

max length = 255

Public Class Methods

attribute_map() click to toggle source

Attribute mapping from ruby-style variable name to JSON key.

# File lib/xero-ruby/models/accounting/address.rb, line 74
def self.attribute_map
  {
    :'address_type' => :'AddressType',
    :'address_line1' => :'AddressLine1',
    :'address_line2' => :'AddressLine2',
    :'address_line3' => :'AddressLine3',
    :'address_line4' => :'AddressLine4',
    :'city' => :'City',
    :'region' => :'Region',
    :'postal_code' => :'PostalCode',
    :'country' => :'Country',
    :'attention_to' => :'AttentionTo'
  }
end
build_from_hash(attributes) click to toggle source

Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself

# File lib/xero-ruby/models/accounting/address.rb, line 353
def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end
new(attributes = {}) click to toggle source

Initializes the object @param [Hash] attributes Model attributes in the form of hash

# File lib/xero-ruby/models/accounting/address.rb, line 107
def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::Accounting::Address` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::Accounting::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'address_type')
    self.address_type = attributes[:'address_type']
  end

  if attributes.key?(:'address_line1')
    self.address_line1 = attributes[:'address_line1']
  end

  if attributes.key?(:'address_line2')
    self.address_line2 = attributes[:'address_line2']
  end

  if attributes.key?(:'address_line3')
    self.address_line3 = attributes[:'address_line3']
  end

  if attributes.key?(:'address_line4')
    self.address_line4 = attributes[:'address_line4']
  end

  if attributes.key?(:'city')
    self.city = attributes[:'city']
  end

  if attributes.key?(:'region')
    self.region = attributes[:'region']
  end

  if attributes.key?(:'postal_code')
    self.postal_code = attributes[:'postal_code']
  end

  if attributes.key?(:'country')
    self.country = attributes[:'country']
  end

  if attributes.key?(:'attention_to')
    self.attention_to = attributes[:'attention_to']
  end
end
openapi_types() click to toggle source

Attribute type mapping.

# File lib/xero-ruby/models/accounting/address.rb, line 90
def self.openapi_types
  {
    :'address_type' => :'String',
    :'address_line1' => :'String',
    :'address_line2' => :'String',
    :'address_line3' => :'String',
    :'address_line4' => :'String',
    :'city' => :'String',
    :'region' => :'String',
    :'postal_code' => :'String',
    :'country' => :'String',
    :'attention_to' => :'String'
  }
end

Public Instance Methods

==(o) click to toggle source

Checks equality by comparing each attribute. @param [Object] Object to be compared

# File lib/xero-ruby/models/accounting/address.rb, line 323
def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      address_type == o.address_type &&
      address_line1 == o.address_line1 &&
      address_line2 == o.address_line2 &&
      address_line3 == o.address_line3 &&
      address_line4 == o.address_line4 &&
      city == o.city &&
      region == o.region &&
      postal_code == o.postal_code &&
      country == o.country &&
      attention_to == o.attention_to
end
_deserialize(type, value) click to toggle source

Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data

# File lib/xero-ruby/models/accounting/address.rb, line 381
def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(parse_date(value))
  when :Date
    Date.parse(parse_date(value))
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BigDecimal
    BigDecimal(value.to_s)
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    XeroRuby::Accounting.const_get(type).build_from_hash(value)
  end
end
_to_hash(value, downcase: false) click to toggle source

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash

# File lib/xero-ruby/models/accounting/address.rb, line 454
def _to_hash(value, downcase: false)
  if value.is_a?(Array)
    value.map do |v|
      v.to_hash(downcase: downcase)
    end
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash(downcase: downcase)
  else
    value
  end
end
address_line1=(address_line1) click to toggle source

Custom attribute writer method with validation @param [Object] address_line1 Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 233
def address_line1=(address_line1)
  if !address_line1.nil? && address_line1.to_s.length > 500
    fail ArgumentError, 'invalid value for "address_line1", the character length must be smaller than or equal to 500.'
  end

  @address_line1 = address_line1
end
address_line2=(address_line2) click to toggle source

Custom attribute writer method with validation @param [Object] address_line2 Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 243
def address_line2=(address_line2)
  if !address_line2.nil? && address_line2.to_s.length > 500
    fail ArgumentError, 'invalid value for "address_line2", the character length must be smaller than or equal to 500.'
  end

  @address_line2 = address_line2
end
address_line3=(address_line3) click to toggle source

Custom attribute writer method with validation @param [Object] address_line3 Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 253
def address_line3=(address_line3)
  if !address_line3.nil? && address_line3.to_s.length > 500
    fail ArgumentError, 'invalid value for "address_line3", the character length must be smaller than or equal to 500.'
  end

  @address_line3 = address_line3
end
address_line4=(address_line4) click to toggle source

Custom attribute writer method with validation @param [Object] address_line4 Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 263
def address_line4=(address_line4)
  if !address_line4.nil? && address_line4.to_s.length > 500
    fail ArgumentError, 'invalid value for "address_line4", the character length must be smaller than or equal to 500.'
  end

  @address_line4 = address_line4
end
address_type=(address_type) click to toggle source

Custom attribute writer method checking allowed values (enum). @param [Object] address_type Object to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 223
def address_type=(address_type)
  validator = EnumAttributeValidator.new('String', ["POBOX", "STREET"])
  unless validator.valid?(address_type)
    fail ArgumentError, "invalid value for \"address_type\", must be one of #{validator.allowable_values}."
  end
  @address_type = address_type
end
attention_to=(attention_to) click to toggle source

Custom attribute writer method with validation @param [Object] attention_to Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 313
def attention_to=(attention_to)
  if !attention_to.nil? && attention_to.to_s.length > 255
    fail ArgumentError, 'invalid value for "attention_to", the character length must be smaller than or equal to 255.'
  end

  @attention_to = attention_to
end
build_from_hash(attributes) click to toggle source

Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself

# File lib/xero-ruby/models/accounting/address.rb, line 360
def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end
city=(city) click to toggle source

Custom attribute writer method with validation @param [Object] city Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 273
def city=(city)
  if !city.nil? && city.to_s.length > 255
    fail ArgumentError, 'invalid value for "city", the character length must be smaller than or equal to 255.'
  end

  @city = city
end
country=(country) click to toggle source

Custom attribute writer method with validation @param [Object] country Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 303
def country=(country)
  if !country.nil? && country.to_s.length > 50
    fail ArgumentError, 'invalid value for "country", the character length must be smaller than or equal to 50.'
  end

  @country = country
end
eql?(o) click to toggle source

@see the `==` method @param [Object] Object to be compared

# File lib/xero-ruby/models/accounting/address.rb, line 340
def eql?(o)
  self == o
end
hash() click to toggle source

Calculates hash code according to all attributes. @return [Integer] Hash code

# File lib/xero-ruby/models/accounting/address.rb, line 346
def hash
  [address_type, address_line1, address_line2, address_line3, address_line4, city, region, postal_code, country, attention_to].hash
end
list_invalid_properties() click to toggle source

Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properties with the reasons

# File lib/xero-ruby/models/accounting/address.rb, line 163
def list_invalid_properties
  invalid_properties = Array.new
  if !@address_line1.nil? && @address_line1.to_s.length > 500
    invalid_properties.push('invalid value for "address_line1", the character length must be smaller than or equal to 500.')
  end

  if !@address_line2.nil? && @address_line2.to_s.length > 500
    invalid_properties.push('invalid value for "address_line2", the character length must be smaller than or equal to 500.')
  end

  if !@address_line3.nil? && @address_line3.to_s.length > 500
    invalid_properties.push('invalid value for "address_line3", the character length must be smaller than or equal to 500.')
  end

  if !@address_line4.nil? && @address_line4.to_s.length > 500
    invalid_properties.push('invalid value for "address_line4", the character length must be smaller than or equal to 500.')
  end

  if !@city.nil? && @city.to_s.length > 255
    invalid_properties.push('invalid value for "city", the character length must be smaller than or equal to 255.')
  end

  if !@region.nil? && @region.to_s.length > 255
    invalid_properties.push('invalid value for "region", the character length must be smaller than or equal to 255.')
  end

  if !@postal_code.nil? && @postal_code.to_s.length > 50
    invalid_properties.push('invalid value for "postal_code", the character length must be smaller than or equal to 50.')
  end

  if !@country.nil? && @country.to_s.length > 50
    invalid_properties.push('invalid value for "country", the character length must be smaller than or equal to 50.')
  end

  if !@attention_to.nil? && @attention_to.to_s.length > 255
    invalid_properties.push('invalid value for "attention_to", the character length must be smaller than or equal to 255.')
  end

  invalid_properties
end
parse_date(datestring) click to toggle source
# File lib/xero-ruby/models/accounting/address.rb, line 470
def parse_date(datestring)
  if datestring.include?('Date')
    date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
    original, date, timezone = *date_pattern.match(datestring)
    date = (date.to_i / 1000)
    Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
  elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
    Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
  else # handle date 'types' for small subset of payroll API's
    Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
  end
end
postal_code=(postal_code) click to toggle source

Custom attribute writer method with validation @param [Object] postal_code Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 293
def postal_code=(postal_code)
  if !postal_code.nil? && postal_code.to_s.length > 50
    fail ArgumentError, 'invalid value for "postal_code", the character length must be smaller than or equal to 50.'
  end

  @postal_code = postal_code
end
region=(region) click to toggle source

Custom attribute writer method with validation @param [Object] region Value to be assigned

# File lib/xero-ruby/models/accounting/address.rb, line 283
def region=(region)
  if !region.nil? && region.to_s.length > 255
    fail ArgumentError, 'invalid value for "region", the character length must be smaller than or equal to 255.'
  end

  @region = region
end
to_attributes() click to toggle source

Returns the object in the form of hash with snake_case

# File lib/xero-ruby/models/accounting/address.rb, line 446
def to_attributes
  to_hash(downcase: true)
end
to_body() click to toggle source

to_body is an alias to to_hash (backward compatibility) @return [Hash] Returns the object in the form of hash

# File lib/xero-ruby/models/accounting/address.rb, line 428
def to_body
  to_hash
end
to_hash(downcase: false) click to toggle source

Returns the object in the form of hash @return [Hash] Returns the object in the form of hash

# File lib/xero-ruby/models/accounting/address.rb, line 434
def to_hash(downcase: false)
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    key = downcase ? attr : param
    hash[key] = _to_hash(value, downcase: downcase)
  end
  hash
end
to_s() click to toggle source

Returns the string representation of the object @return [String] String presentation of the object

# File lib/xero-ruby/models/accounting/address.rb, line 422
def to_s
  to_hash.to_s
end
valid?() click to toggle source

Check to see if the all the properties in the model are valid @return true if the model is valid

# File lib/xero-ruby/models/accounting/address.rb, line 206
def valid?
  address_type_validator = EnumAttributeValidator.new('String', ["POBOX", "STREET"])
  return false unless address_type_validator.valid?(@address_type)
  return false if !@address_line1.nil? && @address_line1.to_s.length > 500
  return false if !@address_line2.nil? && @address_line2.to_s.length > 500
  return false if !@address_line3.nil? && @address_line3.to_s.length > 500
  return false if !@address_line4.nil? && @address_line4.to_s.length > 500
  return false if !@city.nil? && @city.to_s.length > 255
  return false if !@region.nil? && @region.to_s.length > 255
  return false if !@postal_code.nil? && @postal_code.to_s.length > 50
  return false if !@country.nil? && @country.to_s.length > 50
  return false if !@attention_to.nil? && @attention_to.to_s.length > 255
  true
end