forester 0.1.0 → 1.0.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: ca08cece8313d3e3c8b20bae94f78163b81853cb
4
- data.tar.gz: d6b07a8b064d28e35b302a9999f5c45b8a0bcdb2
3
+ metadata.gz: 0b068adf6d25cfadca224f86d1b64a7668fadf5d
4
+ data.tar.gz: 9d4494437e8bc4387b4254217e178a41890c2a3c
5
5
  SHA512:
6
- metadata.gz: 696d7af03b121cba11c01a3fb75aea488edf4a56a415a266bf3c2971f8111358dac17e40a06a110aba00171fd838306034337bbe1b17f9b337c6c91f6676fcd8
7
- data.tar.gz: 3ca6bd73015e51026f8aec700ce061affccea8540db8eedab15b6967ae0421931e5497145a59762c53734ac10502f617f38fb24bab4b9aba756a05f14f7070c1
6
+ metadata.gz: a0e0684ef70d37ddfd9e4751ecaad5a8fe3fcd03d06a33f0f05158882295e31192a09a9478b1dfdf0323f91934827a68c4b78c5dc3ad2624c6ad6e429b248c9a
7
+ data.tar.gz: b5619bcb98e2ca43789f8422cd33c38747997fc695c7dad7bdee14676d728f4cbaa152ea3b4b4b207c2ad53197a1a65e545e857d2febbb42e5e988a581165735
data/forester.gemspec CHANGED
@@ -6,9 +6,9 @@ require 'forester/version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'forester'
8
8
  s.version = Forester::Version
9
- s.date = '2016-07-24'
9
+ s.date = '2016-07-26'
10
10
  s.summary = "A gem to represent and interact with tree data structures"
11
- s.description = "Based on rubytree and enzymator, this gem lets you build trees and run queries against them."
11
+ s.description = "Based on rubytree, this gem lets you build trees and run queries against them."
12
12
  s.authors = ["Eugenio Bruno"]
13
13
  s.email = 'eugeniobruno@gmail.com'
14
14
  s.homepage = 'http://rubygems.org/gems/forester'
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.required_ruby_version = '>= 2.0.0'
23
23
 
24
24
  s.add_runtime_dependency 'rubytree', ['0.9.7']
25
- s.add_runtime_dependency 'enzymator', ['1.0.0']
26
25
 
27
26
  s.add_development_dependency 'rake', ['~> 11.2']
28
27
  s.add_development_dependency 'minitest', ['~> 5.9']
@@ -4,20 +4,41 @@ module Forester
4
4
  def own_and_descendants(options = {})
5
5
  default_options = {
6
6
  field: 'name',
7
- if_field_missing: ->(c) { [] },
7
+ if_field_missing: -> (c) { [] },
8
8
  }
9
9
 
10
10
  options = default_options.merge(options)
11
11
 
12
- Enzymator::Aggregations::MapReduce.new(
13
- {
14
- mapping: ->(node) { Array(node.get(options[:field], &options[:if_field_missing])) },
15
- #reduction: ->(acum, values) { acum.concat(values) },
16
- #empty: []
17
- # automatically assumed
18
- }
19
- )
20
- .run_on(self)
12
+ flat_map do |node|
13
+ Array(node.get(options[:field], &options[:if_field_missing]))
14
+ end
15
+ end
16
+
17
+ def values_by_field(options)
18
+ default_options = {
19
+ field_to_search: 'name',
20
+ search_keyword: :missing_search_keyword,
21
+ values_key: :missing_values_key,
22
+ include_descendants: false,
23
+ assume_uniqueness: false
24
+ }
25
+ options = default_options.merge(options)
26
+
27
+ found_nodes = nodes_with(options[:field_to_search], options[:search_keyword])
28
+
29
+ # When assuming that node names are unique,
30
+ # if more than one node was found,
31
+ # discard all but the first one
32
+ found_nodes = found_nodes.slice(0, 1) if options[:assume_uniqueness]
33
+
34
+ found_nodes.flat_map do |node|
35
+ if options[:include_descendants]
36
+ node.own_and_descendants({ field: options[:values_key] })
37
+ else
38
+ node.get(options[:values_key])
39
+ end
40
+ end
41
+
21
42
  end
22
43
 
23
44
  def values_by_subtree_of_level(options = {})
@@ -25,40 +46,32 @@ module Forester
25
46
  level: 1,
26
47
  group_field: 'name',
27
48
  aggregation_field: 'value',
28
- if_field_missing: ->(c) { [] },
49
+ if_field_missing: -> (c) { [] },
29
50
  include_ancestry_in_keys: false, # if false, with_root is ignored
30
51
  with_root: false,
31
52
  }
32
53
 
33
54
  options = default_options.merge(options)
34
55
 
35
- input = nodes_of_level(options[:level])
36
-
37
- Enzymator::Aggregations::MapReduce.new({
38
- mapping: ->(node) {
39
-
40
- key_nodes = if options[:include_ancestry_in_keys]
41
- node.ancestry(options[:with_root], true)
42
- else
43
- [node]
44
- end
45
-
46
- key = key_nodes.map { |kn| kn.get(options[:group_field]) { |n| n.object_id } }
47
- key = key.first if key.one?
48
-
49
- value = node.own_and_descendants(
50
- {
51
- field: options[:aggregation_field],
52
- if_field_missing: options[:if_field_missing]
53
- }
54
- )
55
-
56
- { key => value }
57
- },
58
- # reduction: ->(acum, hash) { acum.merge(hash) }
59
- # empty: {}
60
- # automatically assumed
61
- }).run_on(input)
56
+ nodes_of_level(options[:level]).each_with_object({}) do |node, hash|
57
+
58
+ key_nodes = if options[:include_ancestry_in_keys]
59
+ node.ancestry(options[:with_root], true)
60
+ else
61
+ node
62
+ end
63
+
64
+ key = key_nodes.map { |kn| kn.get(options[:group_field]) { |n| n.object_id } }
65
+
66
+ value = node.own_and_descendants(
67
+ {
68
+ field: options[:aggregation_field],
69
+ if_field_missing: options[:if_field_missing]
70
+ }
71
+ )
72
+
73
+ hash[key] = value
74
+ end
62
75
  end
63
76
 
64
77
  end
@@ -4,9 +4,9 @@ module Forester
4
4
  include Aggregators
5
5
 
6
6
  def ancestry(include_root = true, include_self = false, descending = true)
7
- ancestors = self.parentage || []
8
- ancestors = ancestors[0...-1] unless include_root
9
- ancestors = ancestors.unshift(self) if include_self
7
+ ancestors = self.parentage || []
8
+ ancestors = ancestors[0...-1] unless include_root
9
+ ancestors = ancestors.unshift(self) if include_self
10
10
  if descending then ancestors.reverse else ancestors end
11
11
  end
12
12
 
@@ -28,33 +28,6 @@ module Forester
28
28
  end
29
29
  end
30
30
 
31
- def values_by_field(options)
32
- default_options = {
33
- field_to_search: 'name',
34
- search_keyword: :missing_search_keyword,
35
- values_key: :missing_values_key,
36
- include_descendants: false,
37
- assume_uniqueness: false
38
- }
39
- options = default_options.merge(options)
40
-
41
- found_nodes = nodes_with(options[:field_to_search], options[:search_keyword])
42
-
43
- # When assuming that node names are unique,
44
- # if more than one node was found,
45
- # discard all but the first one
46
- found_nodes = found_nodes.slice(0, 1) if options[:assume_uniqueness]
47
-
48
- found_nodes.flat_map do |node|
49
- if options[:include_descendants]
50
- node.own_and_descendants({ field: options[:values_key] })
51
- else
52
- node.get(options[:values_key])
53
- end
54
- end
55
-
56
- end
57
-
58
31
  def nodes_with(content_key, content_value)
59
32
  each_node.select { |node| Array(node.get(content_key) { :no_match }).include? content_value }
60
33
  end
@@ -1,7 +1,7 @@
1
1
  module Forester
2
2
  class Version
3
- MAJOR = 0
4
- MINOR = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
5
  PATCH = 0
6
6
  PRE = nil
7
7
 
data/lib/forester.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'tree'
2
- require 'enzymator'
3
2
  require 'securerandom'
4
3
  require 'yaml'
5
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugenio Bruno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubytree
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.7
27
- - !ruby/object:Gem::Dependency
28
- name: enzymator
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 1.0.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +66,8 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: '3.4'
83
- description: Based on rubytree and enzymator, this gem lets you build trees and run
84
- queries against them.
69
+ description: Based on rubytree, this gem lets you build trees and run queries against
70
+ them.
85
71
  email: eugeniobruno@gmail.com
86
72
  executables: []
87
73
  extensions: []