Class: Microstation::TagSets

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/microstation/tag_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drawing, ole) ⇒ TagSets

Returns a new instance of TagSets.



35
36
37
38
39
# File 'lib/microstation/tag_set.rb', line 35

def initialize(drawing,ole)
  raise if ole == nil
  @drawing = drawing
  @ole_obj = ole
end

Instance Attribute Details

#drawingObject (readonly)

Returns the value of attribute drawing.



33
34
35
# File 'lib/microstation/tag_set.rb', line 33

def drawing
  @drawing
end

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



33
34
35
# File 'lib/microstation/tag_set.rb', line 33

def ole_obj
  @ole_obj
end

Instance Method Details

#[](name) ⇒ Object



82
83
84
# File 'lib/microstation/tag_set.rb', line 82

def [](name)
  find(name)
end

#create(name) {|ts| ... } ⇒ Object

Yields:

  • (ts)


100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/microstation/tag_set.rb', line 100

def create(name)
  raise if self[name]
 
  ole = @ole_obj.add(name) rescue binding.pry
 # ts = Tagset.new(ole)

  # yield definer if block_given?

  reset
  ts = self[name]
  raise if ts.nil?
  yield ts if block_given?
  ts
end

#eachObject



67
68
69
70
71
# File 'lib/microstation/tag_set.rb', line 67

def each
  tagsets.each do |obj|
    yield obj
  end
end

#empty?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/microstation/tag_set.rb', line 96

def empty?
  tagsets.empty?
end

#find(name) ⇒ Object



73
74
75
76
# File 'lib/microstation/tag_set.rb', line 73

def find(name)
  return nil if empty?
  tagsets.detect{|ts| ts.name == name}
end

#init_tsObject



41
42
43
44
45
46
47
# File 'lib/microstation/tag_set.rb', line 41

def init_ts
  result = []
  @ole_obj.each do |ts|
    result << TagSet.new(drawing,ts)
  end
  result
end

#lastObject



78
79
80
# File 'lib/microstation/tag_set.rb', line 78

def last
  tagsets[-1]
end

#namesObject



58
59
60
# File 'lib/microstation/tag_set.rb', line 58

def names
  self.map{|ts| ts.name}
end

#remove(name) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/microstation/tag_set.rb', line 86

def remove(name)
  ts = find(name)
  if ts
    @ole_obj.Remove(name) rescue nil
    ts.close
    ts = nil
  end
  reset
end

#resetObject



53
54
55
56
# File 'lib/microstation/tag_set.rb', line 53

def reset
  @tagsets = nil
  @drawing.reset_tagset_instances
end

#sizeObject



113
114
115
# File 'lib/microstation/tag_set.rb', line 113

def size
  tagsets.size
end

#tagsetsObject



63
64
65
# File 'lib/microstation/tag_set.rb', line 63

def tagsets
  @tagsets ||= init_ts
end

#to_sObject



49
50
51
# File 'lib/microstation/tag_set.rb', line 49

def to_s
  "Tagsets: #{tagsets.to_s}"
end