piglet 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ module Piglet
4
4
  SYMBOLIC_OPERATORS = [:==, :>, :<, :>=, :<=, :%, :+, :-, :*, :/]
5
5
  FUNCTIONS = [:avg, :count, :max, :min, :size, :sum, :tokenize]
6
6
 
7
- attr_reader :name, :type, :operator
7
+ attr_reader :name, :type
8
8
 
9
9
  FUNCTIONS.each do |fun|
10
10
  define_method(fun) do
@@ -2,6 +2,8 @@ module Piglet
2
2
  module Field
3
3
  class InfixExpression # :nodoc:
4
4
  include Field
5
+
6
+ attr_reader :operator
5
7
 
6
8
  def initialize(operator, left_expression, right_expression, options=nil)
7
9
  options ||= {}
@@ -2,6 +2,8 @@ module Piglet
2
2
  module Field
3
3
  class PrefixExpression # :nodoc:
4
4
  include Field
5
+
6
+ attr_reader :operator
5
7
 
6
8
  def initialize(operator, expression, space_between=true, options=nil)
7
9
  options ||= {}
@@ -10,7 +12,7 @@ module Piglet
10
12
  end
11
13
 
12
14
  def simple?
13
- true
15
+ false
14
16
  end
15
17
 
16
18
  def to_s
data/lib/piglet.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # :main: README.rdoc
2
2
  module Piglet # :nodoc:
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
 
5
5
  class PigletError < StandardError; end
6
6
  class NotSupportedError < PigletError; end
data/spec/piglet_spec.rb CHANGED
@@ -395,6 +395,13 @@ describe Piglet do
395
395
  end
396
396
 
397
397
  context 'field expressions' do
398
+ it 'parenthesizes expressions with different operators' do
399
+ output = @interpreter.to_pig_latin do
400
+ store(load('in').filter { |r| r.x.and(r.y.or(r.z)).and(r.w) }, 'out')
401
+ end
402
+ output.should include('x AND (y OR z) AND w')
403
+ end
404
+
398
405
  it 'doesn\'t parenthesizes expressions with the same operator' do
399
406
  output = @interpreter.to_pig_latin do
400
407
  store(load('in').filter { |r| r.x.and(r.y.and(r.z)).and(r.w) }, 'out')
@@ -402,11 +409,25 @@ describe Piglet do
402
409
  output.should include('x AND y AND z AND w')
403
410
  end
404
411
 
405
- it 'parenthesizes expressions with different operators' do
412
+ it 'doesn\'t parenthesize function calls' do
406
413
  output = @interpreter.to_pig_latin do
407
- store(load('in').filter { |r| r.x.and(r.y.or(r.z)).and(r.w) }, 'out')
414
+ store(load('in').foreach { |r| [r.x.max + r.y.min] }, 'out')
408
415
  end
409
- output.should include('x AND (y OR z) AND w')
416
+ output.should include('MAX(x) + MIN(y)')
417
+ end
418
+
419
+ it 'doesn\'t parenthesize a suffix expression followed by an infix expression' do
420
+ output = @interpreter.to_pig_latin do
421
+ store(load('in').foreach { |r| [r.x.null?.or(r.y)] }, 'out')
422
+ end
423
+ output.should include('x is null OR y')
424
+ end
425
+
426
+ it 'parenthesizes a prefix expression followed by an infix expression' do
427
+ output = @interpreter.to_pig_latin do
428
+ store(load('in').foreach { |r| [r.x.not.and(r.y)] }, 'out')
429
+ end
430
+ output.should include('(NOT x) AND y')
410
431
  end
411
432
  end
412
433
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piglet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg