[gnome-maps] Move parsing of coordinates to Place module



commit 953547cf5ff5373a04e86c53e561ecd0c3447eae
Author: Alaf Azam <alafazam gmail com>
Date:   Thu Jan 14 16:13:37 2016 +0530

    Move parsing of coordinates to Place module
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744032

 src/place.js      |   23 +++++++++++++++++++++++
 src/placeEntry.js |   25 +------------------------
 2 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/src/place.js b/src/place.js
index 6fb57b5..86bf13a 100644
--- a/src/place.js
+++ b/src/place.js
@@ -25,6 +25,9 @@ const Lang = imports.lang;
 const Location = imports.location;
 const Translations = imports.translations;
 
+// Matches coordinates string with the format "<lat>, <long>"
+const COORDINATES_REGEX = /^\s*(\-?\d+(?:\.\d+)?)\s*,\s*(\-?\d+(?:\.\d+)?)\s*$/;
+
 const Place = new Lang.Class({
     Name: 'Place',
     Extends: Geocode.Place,
@@ -247,3 +250,23 @@ Place.fromJSON = function(obj) {
     }
     return new Place(props);
 };
+
+Place.validateCoordinates = function(lat, lon) {
+    return lat <= 90 && lat >= -90 && lon <= 180 && lon >= -180;
+}
+
+Place.parseCoordinates = function(text) {
+    let match = text.match(COORDINATES_REGEX);
+
+    if (match) {
+        let latitude = parseFloat(match[1]);
+        let longitude = parseFloat(match[2]);
+
+        if (Place.validateCoordinates(latitude, longitude)) {
+            return new Location.Location({ latitude: latitude,
+                                           longitude: longitude });
+        } else
+            return null;
+    } else
+        return null;
+};
\ No newline at end of file
diff --git a/src/placeEntry.js b/src/placeEntry.js
index d418703..b4df702 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -34,9 +34,6 @@ const PlaceStore = imports.placeStore;
 const SearchPopup = imports.searchPopup;
 const Utils = imports.utils;
 
-// Matches coordinates string with the format "<lat>, <long>"
-const COORDINATES_REGEX = /^\s*(\-?\d+(?:\.\d+)?)\s*,\s*(\-?\d+(?:\.\d+)?)\s*$/;
-
 const PlaceEntry = new Lang.Class({
     Name: 'PlaceEntry',
     Extends: Gtk.SearchEntry,
@@ -177,26 +174,6 @@ const PlaceEntry = new Lang.Class({
             return false;
     },
 
-    _validateCoordinates: function(lat, lon) {
-        return lat <= 90 && lat >= -90 && lon <= 180 && lon >= -180;
-    },
-
-    _parseCoordinates: function(text) {
-        let match = text.match(COORDINATES_REGEX);
-
-        if (match) {
-            let latitude = parseFloat(match[1]);
-            let longitude = parseFloat(match[2]);
-
-            if (this._validateCoordinates(latitude, longitude)) {
-                return new Location.Location({ latitude: latitude,
-                                               longitude: longitude });
-            } else
-                return null;
-        } else
-            return null;
-    },
-
     _parse: function() {
         if (this.text.length === 0) {
             this.place = null;
@@ -217,7 +194,7 @@ const PlaceEntry = new Lang.Class({
             return true;
         }
 
-        let parsedLocation = this._parseCoordinates(this.text);
+        let parsedLocation = Place.Place.parseCoordinates(this.text);
         if (parsedLocation) {
             this.place = new Place.Place({ location: parsedLocation });
             return true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]