Class: Rbind::RBase
- Inherits:
-
Object
- Object
- Rbind::RBase
- Defined in:
- lib/rbind/core/rbase.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.cprefix ⇒ Object
Returns the value of attribute cprefix.
Instance Attribute Summary collapse
-
#alias(val = nil) ⇒ Object
Returns the value of attribute alias.
-
#auto_alias ⇒ Object
set to true if rbind is aliasing the object.
-
#cname(name = nil) ⇒ Object
Returns the value of attribute cname.
-
#csignature(sig = nil) ⇒ Object
Returns the value of attribute csignature.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#signature(sig = nil) ⇒ Object
Returns the value of attribute signature.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .basename(name) ⇒ Object
- .namespace(name) ⇒ Object
- .normalize(name) ⇒ Object
- .to_cname(name) ⇒ Object
Instance Method Summary collapse
- #add_flag(*flags) ⇒ Object
- #binding ⇒ Object
- #full_name ⇒ Object
- #generate_signatures ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(name, *flags) ⇒ RBase
constructor
A new instance of RBase.
- #map_to_namespace(name) ⇒ Object
- #namespace? ⇒ Boolean
- #pretty_print(pp) ⇒ Object
- #valid_flags ⇒ Object
- #validate_flags(flags, valid_flags = self.valid_flags) ⇒ Object
Constructor Details
#initialize(name, *flags) ⇒ RBase
Returns a new instance of RBase.
72 73 74 75 76 77 78 79 |
# File 'lib/rbind/core/rbase.rb', line 72 def initialize(name,*flags) name = RBase::normalize(name) raise ArgumentError, "no name" unless name && name.size > 0 @name = RBase::basename(name) @namespace = RBase::namespace(name) @version = 1 self.flags = flags.flatten end |
Class Attribute Details
.cprefix ⇒ Object
Returns the value of attribute cprefix.
16 17 18 |
# File 'lib/rbind/core/rbase.rb', line 16 def cprefix @cprefix end |
Instance Attribute Details
#alias(val = nil) ⇒ Object
Returns the value of attribute alias.
5 6 7 |
# File 'lib/rbind/core/rbase.rb', line 5 def alias @alias end |
#auto_alias ⇒ Object
set to true if rbind is aliasing the object
6 7 8 |
# File 'lib/rbind/core/rbase.rb', line 6 def auto_alias @auto_alias end |
#cname(name = nil) ⇒ Object
Returns the value of attribute cname.
4 5 6 |
# File 'lib/rbind/core/rbase.rb', line 4 def cname @cname end |
#csignature(sig = nil) ⇒ Object
Returns the value of attribute csignature.
12 13 14 |
# File 'lib/rbind/core/rbase.rb', line 12 def csignature @csignature end |
#flags ⇒ Object
Returns the value of attribute flags.
9 10 11 |
# File 'lib/rbind/core/rbase.rb', line 9 def flags @flags end |
#ignore ⇒ Object
Returns the value of attribute ignore.
13 14 15 |
# File 'lib/rbind/core/rbase.rb', line 13 def ignore @ignore end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rbind/core/rbase.rb', line 3 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/rbind/core/rbase.rb', line 7 def namespace @namespace end |
#owner ⇒ Object
Returns the value of attribute owner.
8 9 10 |
# File 'lib/rbind/core/rbase.rb', line 8 def owner @owner end |
#signature(sig = nil) ⇒ Object
Returns the value of attribute signature.
11 12 13 |
# File 'lib/rbind/core/rbase.rb', line 11 def signature @signature end |
#version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/rbind/core/rbase.rb', line 10 def version @version end |
Class Method Details
.basename(name) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rbind/core/rbase.rb', line 48 def basename(name) name = normalize(name) if !!(name =~/.*::(.*)$/) $1 else name end end |
.namespace(name) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rbind/core/rbase.rb', line 57 def namespace(name) name = normalize(name) if !!(name =~/(.*)::.*$/) $1 else nil end end |
.normalize(name) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rbind/core/rbase.rb', line 40 def normalize(name) name = name.to_s if name.split("/n").size > 1 raise "mulitple lines for a name is not supported: #{name}" end name.gsub(".","::").gsub(" ","") end |
.to_cname(name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rbind/core/rbase.rb', line 18 def to_cname(name) name = normalize(name) cn = "#{cprefix}#{name.gsub("::","_")}" cn = cn.gsub("()","_fct") cn = cn.gsub("<=","_smaller_equal") cn = cn.gsub(">=","_greater_equal") cn = cn.gsub("!=","_unequal") cn = cn.gsub("==","_equal") cn = cn.gsub("&=","_and_set") cn = cn.gsub("+=","_add") cn = cn.gsub("-=","_sub") cn = cn.gsub("+","_plus") cn = cn.gsub("-","_minus") cn = cn.gsub("*","_mult") cn = cn.gsub("/","_div") cn = cn.gsub("!","_not") cn = cn.gsub("&","_and") cn = cn.gsub("<","_smaller") cn = cn.gsub(">","_greater") cn.gsub("[]","_array") end |
Instance Method Details
#add_flag(*flags) ⇒ Object
131 132 133 134 |
# File 'lib/rbind/core/rbase.rb', line 131 def add_flag(*flags) @flags += flags self end |
#binding ⇒ Object
178 179 180 |
# File 'lib/rbind/core/rbase.rb', line 178 def binding Kernel.binding end |
#full_name ⇒ Object
166 167 168 |
# File 'lib/rbind/core/rbase.rb', line 166 def full_name map_to_namespace(name) end |
#generate_signatures ⇒ Object
81 82 83 |
# File 'lib/rbind/core/rbase.rb', line 81 def generate_signatures ["#{full_name}","#{cname}"] end |
#ignore? ⇒ Boolean
85 86 87 |
# File 'lib/rbind/core/rbase.rb', line 85 def ignore? !!@ignore end |
#map_to_namespace(name) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/rbind/core/rbase.rb', line 170 def map_to_namespace(name) if namespace "#{namespace}::#{name}" else name end end |
#namespace? ⇒ Boolean
162 163 164 |
# File 'lib/rbind/core/rbase.rb', line 162 def namespace? namespace && namespace.size != 0 end |
#pretty_print(pp) ⇒ Object
68 69 70 |
# File 'lib/rbind/core/rbase.rb', line 68 def pretty_print(pp) pp.text "#{signature}#{" Flags: #{flags.join(", ")}" unless flags.empty?}" end |
#valid_flags ⇒ Object
136 137 138 |
# File 'lib/rbind/core/rbase.rb', line 136 def valid_flags [] end |
#validate_flags(flags, valid_flags = self.valid_flags) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/rbind/core/rbase.rb', line 140 def validate_flags(flags,valid_flags = self.valid_flags) valid_flags.flatten! flags.each do |flag| if !valid_flags.include?(flag) raise "flag #{flag} is not supported for #{self.class.name}. Supported flags are #{valid_flags}" end end end |