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.



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

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.



31
32
33
# File 'lib/microstation/tag_set.rb', line 31

def drawing
  @drawing
end

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



31
32
33
# File 'lib/microstation/tag_set.rb', line 31

def ole_obj
  @ole_obj
end

Instance Method Details

#[](name) ⇒ Object



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

def [](name)
  find(name)
end

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

Yields:

  • (ts)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/microstation/tag_set.rb', line 101

def create(name)
  raise if self[name]

  ole = begin
    @ole_obj.add(name)
  rescue
    binding.pry
  end
  # ts = Tagset.new(ole)

  # yield definer if block_given?

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

  yield ts if block_given?
  ts
end

#each(&block) ⇒ Object



65
66
67
# File 'lib/microstation/tag_set.rb', line 65

def each(&block)
  tagsets.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  tagsets.empty?
end

#find(name) ⇒ Object



69
70
71
72
73
# File 'lib/microstation/tag_set.rb', line 69

def find(name)
  return nil if empty?

  tagsets.detect { |ts| ts.name == name }
end

#init_tsObject



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

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

#lastObject



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

def last
  tagsets[-1]
end

#namesObject



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

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

#remove(name) ⇒ Object



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

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

#resetObject



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

def reset
  @tagsets = nil
  @drawing.reset_tagset_instances
end

#sizeObject



119
120
121
# File 'lib/microstation/tag_set.rb', line 119

def size
  tagsets.size
end

#tagsetsObject



61
62
63
# File 'lib/microstation/tag_set.rb', line 61

def tagsets
  @tagsets ||= init_ts
end

#to_sObject



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

def to_s
  "Tagsets: #{tagsets}"
end