clumpy 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c38353f8705241b8dae34ae95ab52774269ad06
4
- data.tar.gz: 0141cb18954ed27c7a7946dc2b42c63bf19c668d
3
+ metadata.gz: 9bdbfef1adbfd8fb569226453e2d580c65e7a348
4
+ data.tar.gz: 3c199636374d074c3bdb37f5f1f3eb0fa83ee068
5
5
  SHA512:
6
- metadata.gz: a3b4b2c4b12ed391ad8b0bf7df1477bf9138884d133ab5b08dbb142c421f2c51eed95580078980531458fada02911ec63d38d1248101fe556561f644591e84c4
7
- data.tar.gz: 7bcad74a7d125b2a02291ec4108c8c0a5c6e5b801f157edde3a5564bcf7b6e7feb1ce11593aaa652a0070eaeddc15500df30c105848e9408ed75eb96a46524f8
6
+ metadata.gz: 5f97faf5c646c9079980b883adf831e57fe44b3013553bae88101b4bfc84772139b9d548f8bba145c6f09eb6b57c9fcafe30876894bd0adc177d9df9e01acbea
7
+ data.tar.gz: f9cbee56548ea77c69f13d97fc4a379bb01c6ee43252451fd0e2558a18fe6863c4f5342a6fe72bdc38711e79fa376539332c83f15a7906bda8ac3332b341f11f
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ tags
@@ -1 +1 @@
1
- ruby-2.0.0
1
+ ruby-2.1.2
@@ -4,6 +4,8 @@ require "clumpy/cluster_behavior"
4
4
  require "clumpy/cluster"
5
5
  require "clumpy/builder"
6
6
  require "clumpy/extensions/sunspot_hit"
7
+ require "clumpy/extensions/chewy_hit"
8
+ require "clumpy/bounds"
7
9
 
8
10
  module Clumpy
9
11
  end
@@ -0,0 +1,27 @@
1
+ module Clumpy
2
+ class Bounds
3
+ def initialize(latitude, longitude, side_length)
4
+ side_length ||= 10
5
+ @latitude = (latitude - side_length)..(latitude + side_length)
6
+ @longitude = (longitude - side_length*2)..(longitude + side_length*2)
7
+ end
8
+
9
+ attr_reader :latitude
10
+
11
+ attr_reader :longitude
12
+
13
+ def as_json(*)
14
+ {
15
+ northeast: {
16
+ latitude: @latitude.end,
17
+ longitude: @longitude.end,
18
+ },
19
+ southwest: {
20
+ latitude: @latitude.begin,
21
+ longitude: @longitude.begin,
22
+ }
23
+ }
24
+ end
25
+ end
26
+ end
27
+
@@ -8,54 +8,37 @@ module Clumpy
8
8
  @points = [point]
9
9
  @options = options
10
10
 
11
- side_length = options.fetch(:side_length) { 10 }
12
- @bounds = OpenStruct.new(
13
- latitude: (latitude - side_length)..(latitude + side_length),
14
- longitude: (longitude - side_length*2)..(longitude + side_length*2)
15
- )
11
+ @bounds = Bounds.new(@latitude, @longitude, options[:side_length])
16
12
  end
17
13
 
18
14
  def contains?(point)
19
- bounds.latitude.include?(point.latitude) &&
20
- bounds.longitude.include?(point.longitude)
15
+ @bounds.latitude.include?(point.latitude) &&
16
+ @bounds.longitude.include?(point.longitude)
21
17
  end
22
18
 
23
19
  def reposition
24
- @latitude = points.inject(0.0) { |m, p| m + p.latitude } / points.size
25
- @longitude = points.inject(0.0) { |m, p| m + p.longitude } / points.size
20
+ @latitude = @points.inject(0.0) { |m, p| m + p.latitude } / @points.size
21
+ @longitude = @points.inject(0.0) { |m, p| m + p.longitude } / @points.size
26
22
  end
27
23
 
28
24
  def as_json(*)
29
25
  {
30
- latitude: latitude,
26
+ latitude: latitude,
31
27
  longitude: longitude,
32
- size: points.size,
33
- bounds: bounds_as_json,
34
- values: value_list
28
+ size: @points.size,
29
+ bounds: @bounds.as_json,
30
+ values: value_list,
35
31
  }
36
32
  end
37
33
 
38
34
  def value_list
39
35
  case @options[:include_values]
40
- when true then points
36
+ when true then @points
41
37
  when false then []
42
38
  else
43
39
  values_threshold = @options[:values_threshold] || 10
44
- points.size <= values_threshold ? points : []
40
+ @points.size <= values_threshold ? @points : []
45
41
  end
46
42
  end
47
-
48
- def bounds_as_json
49
- {
50
- northeast: {
51
- latitude: bounds.latitude.max,
52
- longitude: bounds.longitude.max
53
- },
54
- southwest: {
55
- latitude: bounds.latitude.min,
56
- longitude: bounds.longitude.min
57
- }
58
- }
59
- end
60
43
  end
61
44
  end
@@ -0,0 +1,20 @@
1
+ module Clumpy
2
+ module Extensions
3
+ module ChewyHit
4
+ def latitude
5
+ @latitude ||= lat.to_f
6
+ end
7
+
8
+ def longitude
9
+ @longitude ||= lng.to_f
10
+ end
11
+
12
+ def as_json(*)
13
+ {
14
+ id: id,
15
+ type: _source.full?(:type) || type.classify
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,11 +2,11 @@ module Clumpy
2
2
  module Extensions
3
3
  module SunspotHit
4
4
  def latitude
5
- stored(:lat)
5
+ @latitude ||= stored(:lat)
6
6
  end
7
7
 
8
8
  def longitude
9
- stored(:lng)
9
+ @longitude ||= stored(:lng)
10
10
  end
11
11
 
12
12
  def as_json(*)
@@ -1,3 +1,3 @@
1
1
  module Clumpy
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clumpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,9 +82,11 @@ files:
82
82
  - Rakefile
83
83
  - clumpy.gemspec
84
84
  - lib/clumpy.rb
85
+ - lib/clumpy/bounds.rb
85
86
  - lib/clumpy/builder.rb
86
87
  - lib/clumpy/cluster.rb
87
88
  - lib/clumpy/cluster_behavior.rb
89
+ - lib/clumpy/extensions/chewy_hit.rb
88
90
  - lib/clumpy/extensions/sunspot_hit.rb
89
91
  - lib/clumpy/version.rb
90
92
  - spec/builder_spec.rb
@@ -111,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
113
  version: '0'
112
114
  requirements: []
113
115
  rubyforge_project:
114
- rubygems_version: 2.1.11
116
+ rubygems_version: 2.2.2
115
117
  signing_key:
116
118
  specification_version: 4
117
119
  summary: Cluster a bunch of points