pomona 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/pomona/extractor.rb +2 -2
- data/lib/pomona/node.rb +13 -0
- data/lib/pomona/tree.rb +8 -3
- data/lib/pomona/version.rb +1 -1
- data/pomona.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f89306f6b8ce71c6e05ac743321e7d04a40a302
|
4
|
+
data.tar.gz: 6ecc22f152e28943c8b27a6b4eef1882a23a9ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b07367e4b7b33fbe22415c274950e268b404d9d56dd14bfac33b8bf97ba46a64bfe546368a8f1451b500f64ac18c07e824d1b5e46a9d05e7e37602b3056a6cae
|
7
|
+
data.tar.gz: 578113e84509dc45dd30dfc1cb36bd2d8f01192037c7601f87ab65da74fa04cd97512642bc317feebb1be2c4b64fb878dd4522bc14d5db64745f65faaee33720
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/ElliottAYoung/Pomona.svg?branch=master)](https://travis-ci.org/ElliottAYoung/Pomona) [![Code Climate](https://codeclimate.com/github/ElliottAYoung/Pomona/badges/gpa.svg)](https://codeclimate.com/github/ElliottAYoung/Pomona) [![Test Coverage](https://codeclimate.com/github/ElliottAYoung/Pomona/badges/coverage.svg)](https://codeclimate.com/github/ElliottAYoung/Pomona/coverage) [![Issue Count](https://codeclimate.com/github/ElliottAYoung/Pomona/badges/issue_count.svg)](https://codeclimate.com/github/ElliottAYoung/Pomona)
|
2
|
+
|
1
3
|
# Pomona
|
2
4
|
|
3
5
|
Pomona is a simple, lightweight gem for creating and managing tree data structures in Ruby. It works using a custom data structure (the Tree) to contain small hashes of data (the Nodes) that can be queried and searched.
|
data/lib/pomona/extractor.rb
CHANGED
@@ -4,7 +4,7 @@ module Extractor
|
|
4
4
|
def self.get_all_by_keys(tree_array = [], keys = [], values = [])
|
5
5
|
tree_array.each do |tree_node|
|
6
6
|
values << tree_node.node.values_at(*keys)
|
7
|
-
Extractor.get_all_by_keys(tree_node.children, keys, values) if tree_node.
|
7
|
+
Extractor.get_all_by_keys(tree_node.children, keys, values) if tree_node.has_children?
|
8
8
|
end
|
9
9
|
|
10
10
|
values
|
@@ -16,7 +16,7 @@ module Extractor
|
|
16
16
|
if tree_node.id == id
|
17
17
|
@target = tree_node
|
18
18
|
else
|
19
|
-
Extractor.find_node_by_id(id, tree_node.children) if tree_node.
|
19
|
+
Extractor.find_node_by_id(id, tree_node.children) if tree_node.has_children?
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/pomona/node.rb
CHANGED
@@ -11,4 +11,17 @@ class Node
|
|
11
11
|
@children = @node[:children]
|
12
12
|
@parent_id = parent_id
|
13
13
|
end
|
14
|
+
|
15
|
+
def has_children?
|
16
|
+
children.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_grandchildren?
|
20
|
+
if has_children?
|
21
|
+
children.select { |child| child.has_children? }.any?
|
22
|
+
else
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
14
27
|
end
|
data/lib/pomona/tree.rb
CHANGED
@@ -27,13 +27,18 @@ class Tree
|
|
27
27
|
|
28
28
|
def values_at(keys)
|
29
29
|
#Returns an array of data from the tree based on the given keys
|
30
|
-
data = Extractor.get_all_by_keys(
|
30
|
+
data = Extractor.get_all_by_keys(nodes, keys)
|
31
31
|
flatten_output_array(data)
|
32
32
|
end
|
33
33
|
|
34
|
+
def nodes
|
35
|
+
#Returns an array of all of the nodes attached to the tree
|
36
|
+
@data[:tree_array]
|
37
|
+
end
|
38
|
+
|
34
39
|
def find(id)
|
35
40
|
#Finds and returns a Node by its id using the Extractor
|
36
|
-
Extractor.find_node_by_id(id,
|
41
|
+
Extractor.find_node_by_id(id, nodes)
|
37
42
|
end
|
38
43
|
|
39
44
|
private
|
@@ -58,7 +63,7 @@ class Tree
|
|
58
63
|
def flatten_output_array(output_array)
|
59
64
|
#Flattens the output array of values_at if it only contains data for one key
|
60
65
|
return output_array if output_array.empty?
|
61
|
-
output_array[0].length == 1 ? output_array.flatten : output_array
|
66
|
+
output_array[0].length == 1 ? output_array.flatten.compact : output_array.compact
|
62
67
|
end
|
63
68
|
|
64
69
|
def find_parent_node(node)
|
data/lib/pomona/version.rb
CHANGED
data/pomona.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pomona
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ElliottAYoung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: A lightweight solution for creating and managing tree data structures
|
70
84
|
email:
|
71
85
|
- elliott.a.young@gmail.com
|