starline 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +8 -2
- data/lib/starline/entities/distance_filter.rb +74 -0
- data/lib/starline/entities/tracks_collection.rb +5 -2
- data/lib/starline/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53f349bc2281f457996dbeb80828b4ad452d4b80
|
4
|
+
data.tar.gz: 54eca28e8d2dcb42abe550efe43c77d3b53070f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b98b07ee62f96e4ba7e97cb4dfba119a1e22b15f4ee84bea977701bdd61141965091874b5b5f0bd25648c3d1f3102f89eed9b98dd36a9eb1d1ea1c85fd7abfa3
|
7
|
+
data.tar.gz: c83e704c404641de1a4866948a9fbea9a7c5c0044042479e3a8e94a133ac37724f66b96db224860b89dca31bb967aed03185545e948ea99dc82bb4d126de4b24
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Starline Telematics
|
2
2
|
|
3
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/sharipov-ru/starline.svg)](https://gemnasium.com/github.com/sharipov-ru/starline)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/sharipov-ru/starline/badges/gpa.svg)](https://codeclimate.com/github/sharipov-ru/starline)
|
5
|
+
[![Build Status](https://travis-ci.org/sharipov-ru/starline.svg?branch=master)](https://travis-ci.org/sharipov-ru/starline)
|
6
|
+
|
3
7
|
StarlineTelematics is a ruby library-wrapper over telematics JSON data from
|
4
8
|
satellite security and monitoring service which is used in StarLine car alarm
|
5
9
|
systems (https://starline-online.ru)
|
@@ -8,6 +12,8 @@ The purpose of the library is to provide easy way for getting your car tracks
|
|
8
12
|
data and present them in usable format for further analyzing / building
|
9
13
|
applications around it.
|
10
14
|
|
15
|
+
The library uses [this fastest available & lightweight implementation](https://github.com/paulnsorensen/fast_haversine) of calculating distance between two points by [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).
|
16
|
+
|
11
17
|
The library is for personal use only and, of course, it doesn't send your data
|
12
18
|
anywhere so you can be confident using it.
|
13
19
|
|
@@ -47,10 +53,10 @@ Get all tracks - connections between geo points:
|
|
47
53
|
telematics.tracks
|
48
54
|
```
|
49
55
|
|
50
|
-
Filter
|
56
|
+
Filter tracks with zero distance:
|
51
57
|
|
52
58
|
```ruby
|
53
|
-
telematics.tracks.
|
59
|
+
telematics.tracks.filter_by_distance(eq: 0)
|
54
60
|
```
|
55
61
|
|
56
62
|
## Development
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Starline
|
2
|
+
module Entities
|
3
|
+
class DistanceFilter
|
4
|
+
# Supported filter names
|
5
|
+
FILTERS = %i(eq ne gt lt gte lte)
|
6
|
+
|
7
|
+
# Mapping between filter names and its ruby functions
|
8
|
+
OPERATORS = {
|
9
|
+
:eq => :==,
|
10
|
+
:ne => :!=,
|
11
|
+
:gt => :>,
|
12
|
+
:lt => :<,
|
13
|
+
:gte => :>=,
|
14
|
+
:lte => :<=
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_reader :type, :value
|
18
|
+
|
19
|
+
# Initialize +DistanceFilter+ object from Hash.
|
20
|
+
#
|
21
|
+
# Usage
|
22
|
+
#
|
23
|
+
# DistanceFilter.new(gt: 5.4)
|
24
|
+
#
|
25
|
+
# Supports only one filter as search parameterfor now.
|
26
|
+
def initialize(search_params_hash)
|
27
|
+
raise_unknown_filter_error if search_params_hash.empty?
|
28
|
+
raise_ambiguous_filter_error if search_params_hash.size > 1
|
29
|
+
|
30
|
+
@type = search_params_hash.keys.first
|
31
|
+
@value = search_params_hash.values.first
|
32
|
+
|
33
|
+
raise_unknown_filter_error unless supported_filter?
|
34
|
+
raise_invalid_value_error unless valid_value?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Applies filter to a given collection.
|
38
|
+
#
|
39
|
+
# Usage
|
40
|
+
#
|
41
|
+
# filter.apply_to(tracks)
|
42
|
+
#
|
43
|
+
# Returns a collection with items which satisfy the current filter
|
44
|
+
def apply_to(collection)
|
45
|
+
collection.select { |item| item.distance.send(operator, @value) }
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def supported_filter?
|
50
|
+
FILTERS.include?(type)
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid_value?
|
54
|
+
value.is_a?(Numeric)
|
55
|
+
end
|
56
|
+
|
57
|
+
def operator
|
58
|
+
OPERATORS[type]
|
59
|
+
end
|
60
|
+
|
61
|
+
def raise_unknown_filter_error
|
62
|
+
raise ArgumentError, "Filter type is unknown"
|
63
|
+
end
|
64
|
+
|
65
|
+
def raise_ambiguous_filter_error
|
66
|
+
raise ArgumentError, "Multiple search parameters are not supported"
|
67
|
+
end
|
68
|
+
|
69
|
+
def raise_invalid_value_error
|
70
|
+
raise ArgumentError, "Filter value must be numeric typed"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'starline/entities/distance_filter'
|
2
|
+
|
1
3
|
module Starline
|
2
4
|
module Entities
|
3
5
|
class TracksCollection
|
@@ -15,8 +17,9 @@ module Starline
|
|
15
17
|
@tracks.size
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
|
20
|
+
def filter_by_distance(search_params_hash)
|
21
|
+
filter = DistanceFilter.new(search_params_hash)
|
22
|
+
filter.apply_to(@tracks)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
data/lib/starline/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharipov Ruslan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_haversine
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/starline/builders.rb
|
106
106
|
- lib/starline/builders/geo_points.rb
|
107
107
|
- lib/starline/builders/tracks.rb
|
108
|
+
- lib/starline/entities/distance_filter.rb
|
108
109
|
- lib/starline/entities/geo_point.rb
|
109
110
|
- lib/starline/entities/track.rb
|
110
111
|
- lib/starline/entities/tracks_collection.rb
|