Class: Incognia::Address

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

Defined Under Namespace

Classes: Coordinates, Line, Structured

Constant Summary collapse

FORMATS =
[:line, :coordinates, :structured].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line: nil, coordinates: {}, structured: {}) ⇒ Address

Returns a new instance of Address.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/incognia_api/address.rb', line 70

def initialize(line: nil, coordinates: {}, structured: {})
  coordinates = Util.symbolize_names(coordinates)
  structured = Util.symbolize_names(structured)

  if line.nil? && coordinates.empty? && structured.empty?
    raise ArgumentError.new(
      "missing keyword: should be one of #{FORMATS.join(', ')}"
    )
  end

  @line = build_line(line)
  @coordinates = build_coordinates(coordinates)
  @structured = build_structured(structured)
end

Instance Attribute Details

#coordinatesObject (readonly)

Returns the value of attribute coordinates.



5
6
7
# File 'lib/incognia_api/address.rb', line 5

def coordinates
  @coordinates
end

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/incognia_api/address.rb', line 5

def line
  @line
end

#structuredObject (readonly)

Returns the value of attribute structured.



5
6
7
# File 'lib/incognia_api/address.rb', line 5

def structured
  @structured
end

Instance Method Details

#to_hashObject



85
86
87
88
89
90
91
# File 'lib/incognia_api/address.rb', line 85

def to_hash
  hash = {}
  hash.merge!(@line.to_hash)
  hash.merge!(@coordinates.to_hash)
  hash.merge!(@structured.to_hash)
  hash
end