Class: Microstation::TS::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/microstation/ts/attribute.rb

Constant Summary collapse

TYPES =

msdTagTypeCharacter 1 (&H1) msdTagTypeShortInteger 2 (&H2) msdTagTypeLongInteger 3 (&H3) msdTagTypeDouble 4 (&H4) msdTagTypeBinary 5 (&H5)

{
  1 => String,
  2 => Integer,
  3 => Integer,
  4 => Float
  #   5 => Binary

}
RUBY_TO_MS =
TYPES.invert

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ole, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



45
46
47
48
# File 'lib/microstation/ts/attribute.rb', line 45

def initialize(ole, options = {})
  @ole_obj = ole
  @definition = options[:definer]
end

Instance Attribute Details

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



4
5
6
# File 'lib/microstation/ts/attribute.rb', line 4

def ole_obj
  @ole_obj
end

Class Method Details

.tag_type(type) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/microstation/ts/attribute.rb', line 22

def self.tag_type(type)
  ruby_type = if type.instance_of?(Symbol)
    case type
    when :char
      String
    when :int
      Integer
    when :float
      Float
    else
      :char
    end
  else
    type
  end

  RUBY_TO_MS[ruby_type]
end

Instance Method Details

#==(other) ⇒ Object



131
132
133
# File 'lib/microstation/ts/attribute.rb', line 131

def ==(other)
  @ole_obj.Name == other.ole_obj.Name && @ole_obj.TagSetName == other.ole_obj.TagSetName && @ole_obj.TagType == other.ole_obj.TagType
end

#att_typeObject



41
42
43
# File 'lib/microstation/ts/attribute.rb', line 41

def att_type
  TYPES[type]
end

#attrib_optionsObject



120
121
122
123
124
125
# File 'lib/microstation/ts/attribute.rb', line 120

def attrib_options
  options = {}
  options[:default] = default_value if has_default?
  options[:readonly] = true if constant?
  options
end

#closeObject



50
51
52
# File 'lib/microstation/ts/attribute.rb', line 50

def close
  @ole_obj = nil
end

#constant=(constant) ⇒ Object



82
83
84
85
# File 'lib/microstation/ts/attribute.rb', line 82

def constant=(constant)
  bool = constant ? true : false
  @ole_obj.IsConstant = bool
end

#constant?Boolean

Returns:

  • (Boolean)


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

def constant?
  @ole_obj.IsConstant
end

#defaultObject



87
88
89
# File 'lib/microstation/ts/attribute.rb', line 87

def default
  @ole_obj.DefaultValue
end

#default=(val) ⇒ Object



91
92
93
# File 'lib/microstation/ts/attribute.rb', line 91

def default=(val)
  @ole_obj.DefaultValue = val
end

#has_default?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/microstation/ts/attribute.rb', line 95

def has_default?
  !!default
end

#hidden=(hidden) ⇒ Object



103
104
105
106
# File 'lib/microstation/ts/attribute.rb', line 103

def hidden=(hidden)
  bool = hidden ? true : false
  @ole_obj.IsHidden = bool
end

#hidden?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/microstation/ts/attribute.rb', line 99

def hidden?
  @ole_obj.IsHidden
end

#nameObject



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

def name
  @ole_obj.name
end

#name=(val) ⇒ Object



62
63
64
# File 'lib/microstation/ts/attribute.rb', line 62

def name=(val)
  @ole_obj.Name = val
end

#options_for_attributeObject



66
67
68
69
70
71
72
# File 'lib/microstation/ts/attribute.rb', line 66

def options_for_attribute
  options = {}
  options[:is_hidden] = true if hidden?
  options[:prompt] = prompt if prompt
  options[:default] = default_value
  options[:readonly] = true if constant?
end

#promptObject



108
109
110
# File 'lib/microstation/ts/attribute.rb', line 108

def prompt
  @ole_obj.Prompt
end

#prompt=(val) ⇒ Object



112
113
114
# File 'lib/microstation/ts/attribute.rb', line 112

def prompt=(val)
  @ole_obj.Prompt = val
end

#tagsetObject



54
55
56
# File 'lib/microstation/ts/attribute.rb', line 54

def tagset
  @definition.tagset if definition
end

#tagset_nameObject



127
128
129
# File 'lib/microstation/ts/attribute.rb', line 127

def tagset_name
  @ole_obj.TagSetName
end

#to_sObject



74
75
76
# File 'lib/microstation/ts/attribute.rb', line 74

def to_s
  "TagDefinition: #{name}"
end

#typeObject



116
117
118
# File 'lib/microstation/ts/attribute.rb', line 116

def type
  TYPES[@ole_obj.TagType]
end