Class: JSE::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/jse/stream.rb

Defined Under Namespace

Classes: FilterChain, TransformChain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inner) ⇒ Stream

Returns a new instance of Stream.



8
9
10
11
12
# File 'lib/jse/stream.rb', line 8

def initialize(inner)
  @inner = inner
  @transforms = []
  @filters = []
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



5
6
7
# File 'lib/jse/stream.rb', line 5

def filters
  @filters
end

#innerObject (readonly)

Returns the value of attribute inner.



6
7
8
# File 'lib/jse/stream.rb', line 6

def inner
  @inner
end

#transformsObject

Returns the value of attribute transforms.



5
6
7
# File 'lib/jse/stream.rb', line 5

def transforms
  @transforms
end

Instance Method Details

#each_lineObject



14
15
16
17
18
19
20
# File 'lib/jse/stream.rb', line 14

def each_line
  inner.each_line do |line|
    unless filter_chain.eliminates?(line)
      yield transform_chain.apply(line)
    end
  end
end

#filter!(field, text, ignore_case = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jse/stream.rb', line 22

def filter!(field, text, ignore_case = false)
  if looks_like_regexp?(text)
    if ignore_case
      filters << RegexpFilter.new(field, text, Regexp::IGNORECASE)
    else
      filters << RegexpFilter.new(field, text)
    end
  else
    if ignore_case
      filters << CaseInsensitiveFilter.new(field, text)
    else
      filters << Filter.new(field, text)
    end
  end
end

#print!(*field_list) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/jse/stream.rb', line 38

def print!(*field_list)
  if field_list.size == 1
    transforms << FieldValueTransform.new(field_list[0])
  else
    transforms << SubsetTransform.new(*field_list)
    transforms << ToJsonTransform.new
  end
end