Class: Masklen::Location

Inherits:
Struct
  • Object
show all
Defined in:
lib/masklen/types.rb

Overview

Geographic location data for an IP address.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#cityObject

Returns the value of attribute city

Returns:

  • (Object)

    the current value of city



3
4
5
# File 'lib/masklen/types.rb', line 3

def city
  @city
end

#countryObject

Returns the value of attribute country

Returns:

  • (Object)

    the current value of country



3
4
5
# File 'lib/masklen/types.rb', line 3

def country
  @country
end

#country_codeObject

Returns the value of attribute country_code

Returns:

  • (Object)

    the current value of country_code



3
4
5
# File 'lib/masklen/types.rb', line 3

def country_code
  @country_code
end

#latitudeObject

Returns the value of attribute latitude

Returns:

  • (Object)

    the current value of latitude



3
4
5
# File 'lib/masklen/types.rb', line 3

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude

Returns:

  • (Object)

    the current value of longitude



3
4
5
# File 'lib/masklen/types.rb', line 3

def longitude
  @longitude
end

#postal_codeObject

Returns the value of attribute postal_code

Returns:

  • (Object)

    the current value of postal_code



3
4
5
# File 'lib/masklen/types.rb', line 3

def postal_code
  @postal_code
end

#regionObject

Returns the value of attribute region

Returns:

  • (Object)

    the current value of region



3
4
5
# File 'lib/masklen/types.rb', line 3

def region
  @region
end

#timezoneObject

Returns the value of attribute timezone

Returns:

  • (Object)

    the current value of timezone



3
4
5
# File 'lib/masklen/types.rb', line 3

def timezone
  @timezone
end

Class Method Details

.from_hash(hash) ⇒ Object

Build a Location from a parsed JSON hash. Returns nil if hash is nil.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/masklen/types.rb', line 15

def self.from_hash(hash)
  return nil if hash.nil?

  new(
    city:         hash["city"],
    region:       hash["region"],
    country:      hash["country"],
    country_code: hash["country_code"],
    latitude:     hash["latitude"],
    longitude:    hash["longitude"],
    postal_code:  hash["postal_code"],
    timezone:     hash["timezone"]
  )
end