Module: RVC::InventoryObject

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjectWithFields::ClassMethods

field, fields

Methods included from ObjectWithFields

#field, #field_properties, #perfmetrics

Instance Attribute Details

#rvc_arcObject (readonly)

Returns the value of attribute rvc_arc.



57
58
59
# File 'lib/rvc/inventory.rb', line 57

def rvc_arc
  @rvc_arc
end

#rvc_parentObject (readonly)

Returns the value of attribute rvc_parent.



57
58
59
# File 'lib/rvc/inventory.rb', line 57

def rvc_parent
  @rvc_parent
end

Class Method Details

.included(m) ⇒ Object



49
50
51
# File 'lib/rvc/inventory.rb', line 49

def self.included m
  m.extend ClassMethods
end

Instance Method Details

#childrenObject



71
72
73
# File 'lib/rvc/inventory.rb', line 71

def children
  {}
end

#display_infoObject



59
60
61
# File 'lib/rvc/inventory.rb', line 59

def display_info
  puts "class: #{self.class.name}"
end

#ls_text(r) ⇒ Object



63
64
65
# File 'lib/rvc/inventory.rb', line 63

def ls_text r
  self.class.folder? ? '/' : ''
end


106
107
108
109
110
# File 'lib/rvc/inventory.rb', line 106

def rvc_link parent, arc
  return if @rvc_parent
  @rvc_parent = parent
  @rvc_arc = arc
end

#rvc_pathObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/rvc/inventory.rb', line 75

def rvc_path
  [].tap do |a|
    cur = self
    while cur != nil
      a << [cur.rvc_arc, cur]
      cur = cur.rvc_parent
    end
    a.reverse!
  end
end

#rvc_path_strObject



86
87
88
# File 'lib/rvc/inventory.rb', line 86

def rvc_path_str
  rvc_path.map { |k,v| k } * '/'
end

#rvc_relative_path(ref) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rvc/inventory.rb', line 90

def rvc_relative_path ref
  my_path = rvc_path
  ref_path = ref.rvc_path
  ref_objs = Set.new(ref_path.map { |x| x[1] })
  common = my_path.take_while { |x| ref_objs.member? x[1] }
  fail unless common
  path_to_ref = my_path.reverse.take_while { |x| x[1] != common.last[1] }.reverse
  num_ups = ref_path.size - common.size
  ups = (['..']*num_ups).zip(ref_path.reverse[1..-1].map(&:first))
  ups + path_to_ref
end

#rvc_relative_path_str(ref) ⇒ Object



102
103
104
# File 'lib/rvc/inventory.rb', line 102

def rvc_relative_path_str ref
  rvc_relative_path(ref).map { |k,v| k } * '/'
end

#traverse_one(arc) ⇒ Object



67
68
69
# File 'lib/rvc/inventory.rb', line 67

def traverse_one arc
  children[arc]
end