Class: Fabulator::Expr::Function
- Inherits:
-
Object
- Object
- Fabulator::Expr::Function
- Defined in:
- lib/fabulator/expr/function.rb
Instance Method Summary collapse
- #expr_type(context) ⇒ Object
-
#initialize(ctx, nom, args) ⇒ Function
constructor
A new instance of Function.
- #run(context, autovivify = false) ⇒ Object
Constructor Details
#initialize(ctx, nom, args) ⇒ Function
Returns a new instance of Function.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fabulator/expr/function.rb', line 4 def initialize(ctx, nom, args) nom.gsub(/\s+/, '') bits = nom.split(/:/, 2) @ns = ctx.get_ns(bits[0]) @name = bits[1] if @name =~ /^(.+)\*$/ @name = "consolidation:#{$1}" end @args = args @ctx = ctx end |
Instance Method Details
#expr_type(context) ⇒ Object
16 17 18 19 20 |
# File 'lib/fabulator/expr/function.rb', line 16 def expr_type(context) return [ FAB_NS, 'boolean' ] if @name =~ /\?$/ klass = TagLib.namespaces[@ns] (klass.function_return_type(@name) rescue nil) end |
#run(context, autovivify = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fabulator/expr/function.rb', line 22 def run(context, autovivify = false) klass = TagLib.namespaces[@ns] return [] if klass.nil? ctx = @ctx.merge(context) ret = klass.run_function( ctx, @name, @args.run(ctx) ) if @name =~ /\?$/ ret = ret.collect{ |v| v.to([FAB_NS, 'boolean']) } end ret end |