class Rushed::Array

Public Class Methods

new(array) click to toggle source
# File lib/rushed/array.rb, line 3
def initialize(array)
  @data = array.to_a
end

Public Instance Methods

==(other) click to toggle source
# File lib/rushed/array.rb, line 67
def ==(other)
  self.to_a == other.to_a
end
each_line() click to toggle source
# File lib/rushed/array.rb, line 7
def each_line
  Rushed::Iterator.new(self)
end
files() click to toggle source
# File lib/rushed/array.rb, line 11
def files
  @data.map! do |line|
    Rushed::File.new(line)
  end
  self
end
format(format='l') click to toggle source
# File lib/rushed/array.rb, line 18
def format(format='l')
  @data.map! do |item|
    item.format(format)
  end
  self
end
grep(pattern) click to toggle source
# File lib/rushed/array.rb, line 25
def grep(pattern)
  if pattern.kind_of?(String)
    pattern = Regexp.new(pattern)
  end
  select! do |item|
    item.to_s =~ pattern
  end
  self
end
map(method=nil, *args, &block) click to toggle source
# File lib/rushed/array.rb, line 35
def map(method=nil, *args, &block)
  if method.nil? && !block_given?
    to_a.map
  elsif method.nil?
    array = to_a.map(&block)
    self.class.new(array)
  else
    array = to_a.map { |item| item.send(method, *args) }
    self.class.new(array)
  end
end
method_missing(method, *args, &block) click to toggle source
# File lib/rushed/array.rb, line 71
def method_missing(method, *args, &block)
  delegate_to_array(method, *args, &block)
end
select(*args, &block) click to toggle source
# File lib/rushed/array.rb, line 47
def select(*args, &block)
  delegate_to_array(:select, *args, &block)
end
to_a() click to toggle source
# File lib/rushed/array.rb, line 55
def to_a
  @data
end
to_ary() click to toggle source
# File lib/rushed/array.rb, line 59
def to_ary
  to_a
end
to_s() click to toggle source
# File lib/rushed/array.rb, line 63
def to_s
  self.to_a.join("\n")
end
to_stdout() click to toggle source
# File lib/rushed/array.rb, line 51
def to_stdout
  self
end

Private Instance Methods

delegate_to_array(method, *args, &block) click to toggle source
# File lib/rushed/array.rb, line 77
def delegate_to_array(method, *args, &block)
  result = to_a.send(method, *args, &block)
  if result.kind_of?(Enumerable)
    self.class.new(result)
  else
    result
  end
end