class Copper::DataTypes::Array

Public Instance Methods

as(clazz) click to toggle source

map the items into the given class

# File lib/copper/data_types/array.rb, line 33
def as(clazz)
        clazz = clazz.capitalize
        found_class = ::Copper::DataTypes::DataType.get_class(clazz)
        return @value.map { |x| found_class.new(x).value }
end
at(index) click to toggle source

get item at index

# File lib/copper/data_types/array.rb, line 24
def at(index)
        if index >= @value.size
                raise RuntimeError, "index #{index} out of bound [0..#{@result.size - 1}]"
        else
                return @value[index]
        end
end
contains(item) click to toggle source
# File lib/copper/data_types/array.rb, line 66
def contains(item)
        @value.include?(item)
end
count() click to toggle source
# File lib/copper/data_types/array.rb, line 5
def count
        return @value.size
end
extract(regex, index) click to toggle source
# File lib/copper/data_types/array.rb, line 39
def extract(regex, index)
        result = []
        @value.each do |v|
                raise RuntimeError, "#{v} is not a String" unless v.is_a?(::String)
                found = v.match(regex)
                result << nil if found.nil?
                result << nil if found[index].nil?
                result << found[index]
        end

        return result
end
first() click to toggle source
# File lib/copper/data_types/array.rb, line 9
def first
        return nil if @value.empty?
        return @value.first
end
in(value) click to toggle source
# File lib/copper/data_types/array.rb, line 19
def in(value)
        @value.include?(value)
end
last() click to toggle source
# File lib/copper/data_types/array.rb, line 14
def last
        return nil if @value.empty?
        return @value.last
end
pick(attribute) click to toggle source
# File lib/copper/data_types/array.rb, line 52
def pick(attribute)
        return @value.map do |x|
                if x.respond_to?(attribute.to_sym)
                        x.send(attribute.to_sym)
                else
                        raise ParseError, "#{attribute} is not a valid attribute on #{x.class.name}"
                end
        end
end
unique() click to toggle source
# File lib/copper/data_types/array.rb, line 62
def unique
        @value.uniq
end