Class: Pebbles::Path::Positions
- Inherits:
-
Object
- Object
- Pebbles::Path::Positions
- Includes:
- Enumerable
- Defined in:
- lib/pebbles-path/positions.rb
Constant Summary collapse
- MAX_DEPTH =
10
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
- #each ⇒ Object
-
#initialize(positions) ⇒ Positions
constructor
A new instance of Positions.
- #resolve(positions) ⇒ Object
- #to_s ⇒ Object
- #truncate_invalid(positions) ⇒ Object
Constructor Details
#initialize(positions) ⇒ Positions
Returns a new instance of Positions.
10 11 12 13 |
# File 'lib/pebbles-path/positions.rb', line 10 def initialize(positions) @all = resolve positions @labels = all.compact end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
9 10 11 |
# File 'lib/pebbles-path/positions.rb', line 9 def all @all end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
9 10 11 |
# File 'lib/pebbles-path/positions.rb', line 9 def labels @labels end |
Class Method Details
.to_conditions(path) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/pebbles-path/positions.rb', line 50 def to_conditions(path) unless Pebbles::Uid::Wildcard.valid?(path) raise ArgumentError.new("Wildcards terminate the path. Invalid path: #{path}") end labels = Pebbles::Uid::Labels.new(path, :name => 'label', :max_depth => MAX_DEPTH, :stop => nil) labels.to_hash end |
Instance Method Details
#[](index) ⇒ Object
19 20 21 |
# File 'lib/pebbles-path/positions.rb', line 19 def [](index) labels[index] end |
#[]=(index, value) ⇒ Object
23 24 25 |
# File 'lib/pebbles-path/positions.rb', line 23 def []=(index, value) labels[index] = value end |
#each ⇒ Object
15 16 17 |
# File 'lib/pebbles-path/positions.rb', line 15 def each labels.each {|label| yield label} end |
#resolve(positions) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/pebbles-path/positions.rb', line 31 def resolve(positions) positions = positions.split('.') if positions.is_a?(String) positions = truncate_invalid(positions) (0...MAX_DEPTH).map do |i| positions[i] end end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/pebbles-path/positions.rb', line 27 def to_s labels.join('.') end |
#truncate_invalid(positions) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/pebbles-path/positions.rb', line 39 def truncate_invalid(positions) labels = [] (0...MAX_DEPTH).each do |i| break if positions[i].nil? labels << positions[i] end labels end |