Class: HTTPLogAnalyzer::Element::Source

Inherits:
HTTPLogAnalyzer::Element show all
Defined in:
lib/http-log-analyzer/element/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HTTPLogAnalyzer::Element

#normalize_uri!, parse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



7
8
9
# File 'lib/http-log-analyzer/element/source.rb', line 7

def address
  @address
end

#cityObject

Returns the value of attribute city.



10
11
12
# File 'lib/http-log-analyzer/element/source.rb', line 10

def city
  @city
end

#countryObject

Returns the value of attribute country.



8
9
10
# File 'lib/http-log-analyzer/element/source.rb', line 8

def country
  @country
end

#regionObject

Returns the value of attribute region.



9
10
11
# File 'lib/http-log-analyzer/element/source.rb', line 9

def region
  @region
end

Instance Method Details

#parse(string) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/http-log-analyzer/element/source.rb', line 12

def parse(string)
  result = $geo_ip.city(string)
  if result
    city, region, country = %i{city_name real_region_name country_name}.map do |key|
      value = result.send(key)
      value.to_s.empty? ? nil : value
    end
    @address = result.ip
    @country = country
    @region = [region, country].join(', ') if region
    @city = [city, region, country].join(', ') if city
  else
    @ip = string
  end
end