fitquery 0.2.0 → 0.4.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDU0ODA5ODBjMTE4NWYxNmQxNWRlNzljMTViMTgxOTAxOThjYjQxYw==
4
+ M2Q0NDlkMGJhZGMzODY0MmJiYTU4N2M2OTRlNjc2NWJkNmQ0Yzg4Nw==
5
5
  data.tar.gz: !binary |-
6
- MjJjN2NhZDFlZjk3Njk0Y2QyOGQxZTM2YzYyMGU5NzdkZWQwODM1Mw==
6
+ Y2JlZmVmMDM1M2RhNTQ5MTljMjI0YjMxZjllYzVjNzljNzZiYzZjZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWIxM2FhY2FjNzRhNWJlYmFjMTBkNjZlZjMwMDJkZWIxMDRkMTNkNjA0OTFi
10
- YWRjYjUzOWIzN2VkOWVjNzRhNWI3MWFmMWI5ZmJlZTFjZTVmMTlkODQ2MDFm
11
- MTIyZGI4YmRkMDhkNjZjNjIyNjVmOTNlYmE2MTE1NzEyODkxYWI=
9
+ ZjljOWU0NzRjNzk2N2M0NWEzY2NmMjZiM2Y1M2I2NDYzNjRkZTBhODJhMGVj
10
+ OTU5N2FmNzRjZGMxMGQxZjJlMjE5ODM1NDMzMGMyZjlhMjRhZDUxODdlMWYw
11
+ MzU2MzZkNTYwNWJjMjBiYjQzZDIwNTAyMjZhNTM5YzkxOWI5YmQ=
12
12
  data.tar.gz: !binary |-
13
- ZjBkZmFiOGRlODQxNjZhZjFhMzNkOGQzYmI2NzgzMjNmYzI0NTE3ZjNkNjk3
14
- NTFlZGMxMDBjMjExODlkODliYjM2ODdlNDQ5YjNiMjM0ZDZmNTU0MWEyYjJk
15
- Y2JkN2U4YjRhYWMyNGI2ZDNlYjRiNmQ0ZDUyZjZhMDlkYTM0NTc=
13
+ ZjZlOTA0N2U5ZDFhMWYyZTA3MGRiMDA2MTQ4ODVlZGJkYzdhNDFjODcxMzVj
14
+ MWM2M2Y2YmM0MTdhZjY1OWJjODZkNjIyMmU4ODFiOTkzNTNkYzM5OTMyMDlm
15
+ MmExNGJhZjBiMzYxZmNkNzNlYjNiYjRiYTJjOTEzZTM3YmVkZDM=
@@ -11,19 +11,24 @@ require 'find'
11
11
  # @attr_reader [FitnesseNode,FitnesseRoot] parent The parent of this node (which may be the root object)
12
12
  # @attr_reader [Array<FitnesseNode>] children The child nodes of this node.
13
13
  # @attr_reader [Pathname] path The path of this node's folder.
14
+ # @attr_reader [Array<String>] path_as_array The path relative to the root, as an array of strings.
14
15
  # @attr_reader [String] name The name of this node. This is the "short" name of the node itself, not the fully qualified name.
15
16
  # @attr_reader [Rexml::Document] properties The properties XML document of this node.
16
17
  # @attr_reader [SortedSet<String>] explicit_tags The set of tags that have been explicitly set on this node.
17
18
  class FitnesseNode
18
- attr_reader :root, :parent, :children, :path, :name, :properties, :explicit_tags
19
+ attr_reader :root, :parent, :children, :path, :path_as_array, :name, :properties, :explicit_tags
19
20
 
20
21
 
21
22
  def initialize(root, parent, name)
22
23
  @root = root
23
24
  @parent = parent
24
25
  @children = []
26
+ @is_root = name == :root
25
27
  @name = name.to_s
26
28
  @path = name == :root ? parent.path : Pathname.new(parent.path.join(name))
29
+ @path_as_array = []
30
+ @path.relative_path_from(@root.path).descend{|partial| @path_as_array.push(partial.basename.to_s)}
31
+
27
32
  begin
28
33
  File.open(@path.join('properties.xml'), 'r') {|f| @properties = REXML::Document.new f }
29
34
  rescue
@@ -108,19 +113,18 @@ class FitnesseNode
108
113
  # @param sep [String] Sets the preferred separator string for the name. If nil, the name will use the system default file path separator.
109
114
  # @return [String] The fully qualified name of the node, consisting of the names of each node in the tree leading to this one.
110
115
  def full_name(sep = nil)
111
- rel_path = @path.relative_path_from(@root.path)
112
- if sep.nil?
113
- rel_path.to_s
114
- else
115
- rel_path.to_s.gsub(Pathname::SEPARATOR_PAT, sep)
116
- end
116
+ separator = sep.nil? ? File::SEPARATOR : sep
117
+ @path_as_array.join(separator)
118
+ end
119
+
120
+ def dotted_name
121
+ full_name('.')
117
122
  end
118
123
 
119
124
  # Gets the depth of this node, i.e. the number of levels down the tree from the root node.
120
125
  # @return [Integer] The depth of the node
121
126
  def depth
122
- rel_path = @path.relative_path_from(@root.path)
123
- rel_path.to_s.scan(Pathname::SEPARATOR_PAT).size
127
+ @path_as_array.length
124
128
  end
125
129
 
126
130
  # Gets the name of the node, prefixed with a number of characters determined by the node's depth.
@@ -183,6 +187,15 @@ class FitnesseNode
183
187
  STDERR.puts(ex.message)
184
188
  end
185
189
 
190
+ # Get the content of the node. Uses lazy loading to avoid slowing down the initial parsing of the tree.
191
+ def content
192
+ @content ||= IO::read(@path.join('content.txt'))
193
+ end
194
+
195
+ def root?
196
+ @is_root
197
+ end
198
+
186
199
  def to_s
187
200
  full_name
188
201
  end
@@ -48,6 +48,25 @@ class FitnesseRoot
48
48
  def find(&block)
49
49
  @root_node.find(&block)
50
50
  end
51
+
52
+ def find_name(name, sep = File::SEPARATOR)
53
+ name_as_array = case name
54
+ when Array then
55
+ name
56
+ when String then
57
+ name.split(sep)
58
+ when Pathname then
59
+ name.to_s.split(File::SEPARATOR)
60
+ else
61
+ raise ArgumentError.new("Name must be an Array, String, or Pathname. Was #{name.class}.")
62
+ end
63
+ find {|node|
64
+ next if node.root?
65
+ full_name = node.path_as_array
66
+ Find.prune unless (full_name - name_as_array).empty?
67
+ return node if full_name == name_as_array
68
+ }
69
+ end
51
70
  end
52
71
 
53
72
 
@@ -1,3 +1,3 @@
1
1
  module Fitquery
2
- VERSION = '0.2.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Peguero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler