Class: HTTPLogAnalyzer::Element::Source
- Inherits:
-
HTTPLogAnalyzer::Element
- Object
- HTTPLogAnalyzer::Element
- HTTPLogAnalyzer::Element::Source
- Defined in:
- lib/http-log-analyzer/element/source.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#region ⇒ Object
Returns the value of attribute region.
Instance Method Summary collapse
Methods inherited from HTTPLogAnalyzer::Element
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/http-log-analyzer/element/source.rb', line 7 def address @address end |
#city ⇒ Object
Returns the value of attribute city.
10 11 12 |
# File 'lib/http-log-analyzer/element/source.rb', line 10 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
8 9 10 |
# File 'lib/http-log-analyzer/element/source.rb', line 8 def country @country end |
#region ⇒ Object
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 |