Class: Fabulator::TagLib
- Inherits:
-
Object
- Object
- Fabulator::TagLib
- Defined in:
- lib/fabulator/tag_lib.rb,
lib/fabulator/tag_lib/type.rb,
lib/fabulator/tag_lib/presentations.rb,
lib/fabulator/tag_lib/transformations.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods, Util Classes: Format, Presentations, Transformations, Type, TypeConversion
Constant Summary collapse
- @@action_descriptions =
{}
- @@structural_descriptions =
{}
- @@structural_classes =
{}
- @@function_descriptions =
{}
- @@function_args =
{ }
- @@namespaces =
{}
- @@attributes =
[ ]
- @@last_description =
nil
- @@presentations =
{ }
- @@types =
{ }
- @@axes =
{ }
Class Method Summary collapse
- .action_descriptions ⇒ Object
- .action_descriptions=(x) ⇒ Object
- .attributes ⇒ Object
- .attributes=(x) ⇒ Object
- .axes ⇒ Object
- .axes=(x) ⇒ Object
- .current_super ⇒ Object
- .find_op(t, o) ⇒ Object
- .function_args ⇒ Object
- .function_args=(x) ⇒ Object
- .function_description ⇒ Object
- .function_description=(x) ⇒ Object
- .inherited(base) ⇒ Object
- .last_description ⇒ Object
- .last_description=(x) ⇒ Object
- .namespaces ⇒ Object
- .namespaces=(x) ⇒ Object
- .presentations ⇒ Object
- .presentations=(x) ⇒ Object
- .structural_classes ⇒ Object
- .structural_classes=(x) ⇒ Object
- .structural_descriptions ⇒ Object
- .structural_descriptions=(x) ⇒ Object
- .type_handler(t) ⇒ Object
- .type_path(from, to) ⇒ Object
- .types ⇒ Object
- .types=(x) ⇒ Object
-
.unify_types(ts) ⇒ Object
returns nil if no common type can be found.
- .with_super(s, &block) ⇒ Object
Instance Method Summary collapse
- #action_descriptions(hash = nil) ⇒ Object
- #action_exists?(nom) ⇒ Boolean
- #compile_action(e, c) ⇒ Object
- #compile_structural(e, c) ⇒ Object
- #function_args(hash = nil) ⇒ Object
- #function_descriptions(hash = nil) ⇒ Object
- #function_return_type(name) ⇒ Object
- #function_run_scaling(name) ⇒ Object
- #function_run_type(name) ⇒ Object
- #presentation ⇒ Object
- #run_constraint(context, nom) ⇒ Object
- #run_filter(context, nom) ⇒ Object
- #run_function(context, nom, args, depth = 0) ⇒ Object
- #structural_class(nom) ⇒ Object
Class Method Details
.action_descriptions ⇒ Object
21 22 23 |
# File 'lib/fabulator/tag_lib.rb', line 21 def self.action_descriptions @@action_descriptions end |
.action_descriptions=(x) ⇒ Object
55 56 57 |
# File 'lib/fabulator/tag_lib.rb', line 55 def self.action_descriptions=(x) @@action_descriptions = x end |
.attributes ⇒ Object
36 37 38 |
# File 'lib/fabulator/tag_lib.rb', line 36 def self.attributes @@attributes end |
.attributes=(x) ⇒ Object
70 71 72 |
# File 'lib/fabulator/tag_lib.rb', line 70 def self.attributes=(x) @@attributes = x end |
.axes ⇒ Object
42 43 44 |
# File 'lib/fabulator/tag_lib.rb', line 42 def self.axes @@axes end |
.axes=(x) ⇒ Object
76 77 78 |
# File 'lib/fabulator/tag_lib.rb', line 76 def self.axes=(x) @@axes = x end |
.current_super ⇒ Object
143 144 145 146 |
# File 'lib/fabulator/tag_lib.rb', line 143 def self.current_super return nil if @@super.nil? || @@super.empty? return @@super.first end |
.find_op(t, o) ⇒ Object
95 96 97 |
# File 'lib/fabulator/tag_lib.rb', line 95 def self.find_op(t,o) ( self.type_handler(t).get_method(t[0] + o.to_s.upcase) rescue nil ) end |
.function_args ⇒ Object
33 34 35 |
# File 'lib/fabulator/tag_lib.rb', line 33 def self.function_args @@function_args end |
.function_args=(x) ⇒ Object
67 68 69 |
# File 'lib/fabulator/tag_lib.rb', line 67 def self.function_args=(x) @@function_args = x end |
.function_description ⇒ Object
30 31 32 |
# File 'lib/fabulator/tag_lib.rb', line 30 def self.function_description @@function_description end |
.function_description=(x) ⇒ Object
64 65 66 |
# File 'lib/fabulator/tag_lib.rb', line 64 def self.function_description=(x) @@function_description = x end |
.inherited(base) ⇒ Object
87 88 89 |
# File 'lib/fabulator/tag_lib.rb', line 87 def self.inherited(base) base.extend(ClassMethods) end |
.last_description ⇒ Object
15 16 17 |
# File 'lib/fabulator/tag_lib.rb', line 15 def self.last_description @@last_description end |
.last_description=(x) ⇒ Object
49 50 51 |
# File 'lib/fabulator/tag_lib.rb', line 49 def self.last_description=(x) @@last_description = x end |
.namespaces ⇒ Object
18 19 20 |
# File 'lib/fabulator/tag_lib.rb', line 18 def self.namespaces @@namespaces end |
.namespaces=(x) ⇒ Object
52 53 54 |
# File 'lib/fabulator/tag_lib.rb', line 52 def self.namespaces=(x) @@namespaces = x end |
.presentations ⇒ Object
45 46 47 |
# File 'lib/fabulator/tag_lib.rb', line 45 def self.presentations @@presentations end |
.presentations=(x) ⇒ Object
79 80 81 |
# File 'lib/fabulator/tag_lib.rb', line 79 def self.presentations=(x) @@presentations = x end |
.structural_classes ⇒ Object
27 28 29 |
# File 'lib/fabulator/tag_lib.rb', line 27 def self.structural_classes @@structural_classes end |
.structural_classes=(x) ⇒ Object
61 62 63 |
# File 'lib/fabulator/tag_lib.rb', line 61 def self.structural_classes=(x) @@structural_classes = x end |
.structural_descriptions ⇒ Object
24 25 26 |
# File 'lib/fabulator/tag_lib.rb', line 24 def self.structural_descriptions @@structural_descriptions end |
.structural_descriptions=(x) ⇒ Object
58 59 60 |
# File 'lib/fabulator/tag_lib.rb', line 58 def self.structural_descriptions=(x) @@structural_descriptions = x end |
.type_handler(t) ⇒ Object
91 92 93 |
# File 'lib/fabulator/tag_lib.rb', line 91 def self.type_handler(t) (@@types[t[0]][t[1].to_sym] rescue nil) end |
.type_path(from, to) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/fabulator/tag_lib.rb', line 129 def self.type_path(from, to) return [] if from.nil? || to.nil? || from.join('') == to.join('') from_obj = self.type_handler(from) return [] if from_obj.nil? return from_obj.build_conversion_to(to) end |
.types ⇒ Object
39 40 41 |
# File 'lib/fabulator/tag_lib.rb', line 39 def self.types @@types end |
.types=(x) ⇒ Object
73 74 75 |
# File 'lib/fabulator/tag_lib.rb', line 73 def self.types=(x) @@types = x end |
.unify_types(ts) ⇒ Object
returns nil if no common type can be found
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fabulator/tag_lib.rb', line 100 def self.unify_types(ts) # breadth-first search from all ts to find common type that # we can convert to. We have to check all levels each time # in case one of the initial types becomes a common type across # all ts return nil if ts.empty? || ts.include?(nil) # now group by types since we only need one of each type for unification grouped = { } ts.each do |t| t = t.vtype.collect{ |i| i.to_s} unless t.is_a?(Array) grouped[t.join('')] = t end grouped = grouped.values return grouped.first if grouped.size == 1 # now we unify based on the first two and then adding one each time # until we unify all of them t1 = grouped.pop t2 = grouped.pop t1_obj = self.type_handler(t1) ut = t1_obj.unify_with_type(t2) return nil if ut.nil? self.unify_types([ ut[:t] ] + grouped) end |
.with_super(s, &block) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/fabulator/tag_lib.rb', line 136 def self.with_super(s, &block) @@super ||= [] # not thread safe :-/ @@super.unshift(s) yield @@super.shift end |
Instance Method Details
#action_descriptions(hash = nil) ⇒ Object
250 251 252 |
# File 'lib/fabulator/tag_lib.rb', line 250 def action_descriptions(hash=nil) self.class.action_descriptions hash end |
#action_exists?(nom) ⇒ Boolean
160 161 162 |
# File 'lib/fabulator/tag_lib.rb', line 160 def action_exists?(nom) self.respond_to?("action:#{nom.to_s}") end |
#compile_action(e, c) ⇒ Object
148 149 150 151 152 |
# File 'lib/fabulator/tag_lib.rb', line 148 def compile_action(e, c) if self.class.method_defined? "action:#{e.name}" send "action:#{e.name}", e, c #.merge(e) end end |
#compile_structural(e, c) ⇒ Object
154 155 156 157 158 |
# File 'lib/fabulator/tag_lib.rb', line 154 def compile_structural(e, c) if self.class.method_defined? "structural:#{e.name}" send "structural:#{e.name}", e, c end end |
#function_args(hash = nil) ⇒ Object
231 232 233 |
# File 'lib/fabulator/tag_lib.rb', line 231 def function_args @function_args ||= { } end |
#function_descriptions(hash = nil) ⇒ Object
254 255 256 |
# File 'lib/fabulator/tag_lib.rb', line 254 def function_descriptions(hash=nil) self.class.function_descriptions hash end |
#function_return_type(name) ⇒ Object
211 212 213 |
# File 'lib/fabulator/tag_lib.rb', line 211 def function_return_type(name) (self.function_descriptions[name.to_sym][:returns] rescue nil) end |
#function_run_scaling(name) ⇒ Object
215 216 217 |
# File 'lib/fabulator/tag_lib.rb', line 215 def function_run_scaling(name) (self.function_descriptions[name.to_sym][:scaling] rescue nil) end |
#function_run_type(name) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/fabulator/tag_lib.rb', line 219 def function_run_type(name) r = (self.function_descriptions[name.to_sym][:type] rescue nil) if r.nil? && !self.function_descriptions.has_key?(name.to_sym) if name =~ /^consolidation:(.*)/ if function_run_scaling($1) != :flat return :consolidation end end end r end |
#presentation ⇒ Object
262 263 264 |
# File 'lib/fabulator/tag_lib.rb', line 262 def presentation self.class.presentation end |
#run_constraint(context, nom) ⇒ Object
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/fabulator/tag_lib.rb', line 239 def run_constraint(context, nom) context = [ context ] unless context.is_a?(Array) paths = [ [], [] ] context.each do |c| p = send("constraint:#{nom}", c) paths[0] += p[0] paths[1] += p[1] end return [ (paths[0] - paths[1]).uniq, paths[1].uniq ] end |
#run_filter(context, nom) ⇒ Object
235 236 237 |
# File 'lib/fabulator/tag_lib.rb', line 235 def run_filter(context, nom) send "filter:#{nom}", context end |
#run_function(context, nom, args, depth = 0) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/fabulator/tag_lib.rb', line 164 def run_function(context, nom, args, depth=0) ret = [] #begin case self.function_run_type(nom) when :mapping ret = args.flatten.collect { |a| send "fctn:#{nom}", context, a } when :reduction ret = send "fctn:#{nom}", context, args.flatten when :consolidation if respond_to?("fctn:#{nom}") ret = send "fctn:#{nom}", context, args.flatten elsif nom =~ /^consolidation:(.*)$/ ret = send "fctn:#{$1}", context, args.flatten else ret = [ ] end else ret = send "fctn:#{nom}", context, args end #rescue => e # raise "function #{nom} raised #{e}" #end ret = [ ret ] unless ret.is_a?(Array) ret = ret.flatten.collect{ |r| if r.is_a?(Fabulator::Expr::Node) r elsif r.is_a?(Hash) rr = context.root.anon_node(nil, nil) r.each_pair do |k,v| rrr = context.root.anon_node(v) #, self.function_return_type(nom)) rrr.name = k rr.add_child(rrr) end rr else rt = self.function_return_type(nom) if rt.nil? context.root.anon_node(r) #, self.function_return_type(nom)) else context.root.anon_node(r,rt) end end } ret.flatten end |
#structural_class(nom) ⇒ Object
83 84 85 |
# File 'lib/fabulator/tag_lib.rb', line 83 def structural_class(nom) Fabulator::TagLib.structural_classes[self.class.name][nom.to_sym] end |