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.
-
#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.
67 68 69 70 71 72 73 74 |
# File 'lib/rbind/core/rbase.rb', line 67 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.
15 16 17 |
# File 'lib/rbind/core/rbase.rb', line 15 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 |
#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.
11 12 13 |
# File 'lib/rbind/core/rbase.rb', line 11 def csignature @csignature end |
#flags ⇒ Object
Returns the value of attribute flags.
8 9 10 |
# File 'lib/rbind/core/rbase.rb', line 8 def flags @flags end |
#ignore ⇒ Object
Returns the value of attribute ignore.
12 13 14 |
# File 'lib/rbind/core/rbase.rb', line 12 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.
6 7 8 |
# File 'lib/rbind/core/rbase.rb', line 6 def namespace @namespace end |
#owner ⇒ Object
Returns the value of attribute owner.
7 8 9 |
# File 'lib/rbind/core/rbase.rb', line 7 def owner @owner end |
#signature(sig = nil) ⇒ Object
Returns the value of attribute signature.
10 11 12 |
# File 'lib/rbind/core/rbase.rb', line 10 def signature @signature end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/rbind/core/rbase.rb', line 9 def version @version end |
Class Method Details
.basename(name) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/rbind/core/rbase.rb', line 43 def basename(name) name = normalize(name) if !!(name =~/.*::(.*)$/) $1 else name end end |
.namespace(name) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/rbind/core/rbase.rb', line 52 def namespace(name) name = normalize(name) if !!(name =~/(.*)::.*$/) $1 else nil end end |
.normalize(name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rbind/core/rbase.rb', line 35 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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbind/core/rbase.rb', line 17 def to_cname(name) name = normalize(name) cn = "#{cprefix}#{name.gsub("::","_")}" cn = cn.gsub("()","_fct") 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.gsub("[]","_array") end |
Instance Method Details
#add_flag(*flags) ⇒ Object
126 127 128 129 |
# File 'lib/rbind/core/rbase.rb', line 126 def add_flag(*flags) @flags += flags self end |
#binding ⇒ Object
173 174 175 |
# File 'lib/rbind/core/rbase.rb', line 173 def binding Kernel.binding end |
#full_name ⇒ Object
161 162 163 |
# File 'lib/rbind/core/rbase.rb', line 161 def full_name map_to_namespace(name) end |
#generate_signatures ⇒ Object
76 77 78 |
# File 'lib/rbind/core/rbase.rb', line 76 def generate_signatures ["#{full_name}","#{cname}"] end |
#ignore? ⇒ Boolean
80 81 82 |
# File 'lib/rbind/core/rbase.rb', line 80 def ignore? !!@ignore end |
#map_to_namespace(name) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/rbind/core/rbase.rb', line 165 def map_to_namespace(name) if namespace "#{namespace}::#{name}" else name end end |
#namespace? ⇒ Boolean
157 158 159 |
# File 'lib/rbind/core/rbase.rb', line 157 def namespace? namespace && namespace.size != 0 end |
#pretty_print(pp) ⇒ Object
63 64 65 |
# File 'lib/rbind/core/rbase.rb', line 63 def pretty_print(pp) pp.text "#{signature}#{" Flags: #{flags.join(", ")}" unless flags.empty?}" end |
#valid_flags ⇒ Object
131 132 133 |
# File 'lib/rbind/core/rbase.rb', line 131 def valid_flags [] end |
#validate_flags(flags, valid_flags = self.valid_flags) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/rbind/core/rbase.rb', line 135 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 |