starline 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 479179b8a62f12f04476cd6ba6f653b9f4d86406
4
- data.tar.gz: 925f4f70aa604a3e3ee7250f215a7ccbe83334a8
3
+ metadata.gz: 53f349bc2281f457996dbeb80828b4ad452d4b80
4
+ data.tar.gz: 54eca28e8d2dcb42abe550efe43c77d3b53070f9
5
5
  SHA512:
6
- metadata.gz: fddb071ac90be7118bbd5f4dbcb0d52e8fe6263f89bbe308fa356de00a37a392f1cb245eb304cd25e2f7251a5fa42e87532067736f587c920c4429b94bf3b5c8
7
- data.tar.gz: c8774aca9f5724b4b5611d4ecdd28c4dd10639b7efc4921e079ece28e45f273c92a29ca613e550434d3ed9b927b313b18eaf50f90e7ebd4b7031b3021cb96eae
6
+ metadata.gz: b98b07ee62f96e4ba7e97cb4dfba119a1e22b15f4ee84bea977701bdd61141965091874b5b5f0bd25648c3d1f3102f89eed9b98dd36a9eb1d1ea1c85fd7abfa3
7
+ data.tar.gz: c83e704c404641de1a4866948a9fbea9a7c5c0044042479e3a8e94a133ac37724f66b96db224860b89dca31bb967aed03185545e948ea99dc82bb4d126de4b24
@@ -1,5 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.3
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
5
7
  before_install: gem install bundler -v 1.12.5
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 out tracks when with zero distance:
56
+ Filter tracks with zero distance:
51
57
 
52
58
  ```ruby
53
- telematics.tracks.without_parking_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 without_parking_tracks
19
- @tracks.reject { |track| track.distance == 0 }
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
@@ -1,3 +1,3 @@
1
1
  module Starline
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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: 2016-06-08 00:00:00.000000000 Z
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