Class: Expressive::TopLevel
Instance Attribute Summary
Attributes inherited from Scope
Instance Method Summary collapse
-
#initialize ⇒ TopLevel
constructor
A new instance of TopLevel.
- #to_hash ⇒ Object
Methods inherited from Scope
#[], #[]=, #add_lookup_function, #add_lookup_table, #clear_lookup_tables, #define, #include?, #merge, #override_scope, #retrieve_scope, #syntax
Constructor Details
#initialize ⇒ TopLevel
Returns a new instance of TopLevel.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/scope.rb', line 74 def initialize super syntax('set') do |scope, cells| scope[cells.first.text_value] = cells[1].eval(scope) end syntax('$append') do |scope, cells| scope[cells.first.text_value] = [] if scope[cells.first.text_value].nil? addition = cells[1].eval(scope) if addition.is_a?(Array) scope[cells.first.text_value] = scope[cells.first.text_value] | addition else scope[cells.first.text_value] << addition end end syntax('$lookup') {|scope, cells| perform_lookup(scope, cells)} syntax('lookup') {|scope, cells| perform_lookup(scope, cells)} syntax('post') do |scope, cells| perform_webhook(:post, scope, cells) end syntax('put') do |scope, cells| perform_webhook(:put, scope, cells) end syntax('get') do |scope, cells| perform_webhook(:get, scope, cells) end syntax('date') do |scope, cells| if cells.empty? Date.today.to_time.utc else date = cells.first.text_value.gsub(/[\)\(]/, '') values = date.split('/').map(&:to_i).reverse Date.new(values[0], values[1], values[2]).to_time.utc end end define('$id') {|*args| args.first.id } define('+') {|a,b| a.to_f + b.to_f } define('-') {|a,b| a.to_f - b.to_f } define('*') {|a,b| a.to_f * b.to_f } define('/') {|a,b| a.to_f / b.to_f } define('=') {|a,b| a == b } define('>') {|a,b| a.to_f > b.to_f } define('<') {|a,b| a.to_f < b.to_f } define('>=') {|a,b| a.to_f >= b.to_f } define('<=') {|a,b| a.to_f <= b.to_f } define('and') {|a,b| !!a && !!b } define('or') {|a,b| !!a || !!b } define('sum') {|*args| args.flatten.map(&:to_f).reduce(:+) || 0 } define('$sub') {|*args| result = args.flatten.map(&:to_f).reduce(:-) || 0 } define('if') {|*args| args.compact!; args[0] ? args[1] : args[2] } define('$days_ago'){|*args| Time.now - args[0].to_i * 86400 } define('$hours_ago'){|*args| Time.now - args[0].to_i * 3600 } define('$minutes_ago'){|*args| Time.now - args[0].to_i * 60 } define('$head'){|*args| args.flatten.first } define('$tail'){|*args| args.flatten[1..-1] } define('$reverse'){|*args| args.flatten.reverse } define('$round'){|*args| perform_round(args) } define('round'){|*args| perform_round(args) } end |
Instance Method Details
#to_hash ⇒ Object
144 145 146 147 |
# File 'lib/scope.rb', line 144 def to_hash h = self.retrieve_scope.dup h.delete_if{|k, v| v.kind_of?(Expressive::Function) || v.kind_of?(Expressive::ExtendedValue)} end |