pomona 0.6.0 → 0.7.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: e46fd3f505f3d16d9a6e52dccb81777709281e31
4
- data.tar.gz: 68c792bc59061bc4885f1184879a8ac059d53b39
3
+ metadata.gz: 9f89306f6b8ce71c6e05ac743321e7d04a40a302
4
+ data.tar.gz: 6ecc22f152e28943c8b27a6b4eef1882a23a9ae0
5
5
  SHA512:
6
- metadata.gz: 6156620e8aeaf867c94b28cd19ae5c68d7149da1a3b82ce36c2db1ac891be11326ca993b9d7cfd472084c3fae54e71b525e034ef8d9b9775d224d24edd2bdf25
7
- data.tar.gz: 7fc7ed2ac3c3e316c8c9f9919b776402ca4f7fce5e1ff5caa02f58318d8efb0458578843cdec48d860522903dc3b748b07b54df80c79110a269e1c7d4fb4e9e8
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.
@@ -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.children.any?
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.children.any?
19
+ Extractor.find_node_by_id(id, tree_node.children) if tree_node.has_children?
20
20
  end
21
21
  end
22
22
 
@@ -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
@@ -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(@data[:tree_array], 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, @data[:tree_array])
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)
@@ -1,3 +1,3 @@
1
1
  module Pomona
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "pry"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "codeclimate-test-reporter"
25
26
  end
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.6.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-07-07 00:00:00.000000000 Z
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