Class: EOAT::Result::EveType::RowSet

Inherits:
Object
  • Object
show all
Defined in:
lib/eoat/result/eve_type.rb

Overview

Rowset container for xml data. Usually not called directly

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ RowSet

Returns a new instance of RowSet.

Parameters:

  • hash (Hash)

    the roset value from xml as hash



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
# File 'lib/eoat/result/eve_type.rb', line 100

def initialize(hash)
  @key = hash['key']
  @columns = hash['columns'].split(',')
  @name = hash['name']
  if hash.key? 'row'
    case hash['row']
      when Array
        @entries = Array.new(hash['row'].map.each {|row| Row.new(row)})
      when Hash
        @entries = Array.new(1, Row.new(hash['row']))
      else
        raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{hash['row']}"
    end
  else
    @entries = Array.new
  end
  @entries_index = Hash.new
  if @key
    @entries.each_with_index do |record, i|
      key = record.public_send(@key).to_i
        if @entries_index.key? key
          case @entries_index[key]
            when Array
              @entries_index[key] << i
            when Fixnum, Integer
              @entries_index[key] = [@entries_index[key], i]
            else
              # nothing
          end
        else
          @entries_index[key] = i
        end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/eoat/result/eve_type.rb', line 152

def method_missing(meth, *args, &block)
  if instance_variable_defined?("@#{meth.to_s}")
    instance_variable_get("@#{meth.to_s}")
  else
    super
  end
end

Instance Attribute Details

#columnsObject

The array of methods names for Row class



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/eoat/result/eve_type.rb', line 96

class RowSet
  attr_accessor :key, :columns, :entries, :entries_index

  # @param [Hash] hash the roset value from xml as hash
  def initialize(hash)
    @key = hash['key']
    @columns = hash['columns'].split(',')
    @name = hash['name']
    if hash.key? 'row'
      case hash['row']
        when Array
          @entries = Array.new(hash['row'].map.each {|row| Row.new(row)})
        when Hash
          @entries = Array.new(1, Row.new(hash['row']))
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{hash['row']}"
      end
    else
      @entries = Array.new
    end
    @entries_index = Hash.new
    if @key
      @entries.each_with_index do |record, i|
        key = record.public_send(@key).to_i
          if @entries_index.key? key
            case @entries_index[key]
              when Array
                @entries_index[key] << i
              when Fixnum, Integer
                @entries_index[key] = [@entries_index[key], i]
              else
                # nothing
            end
          else
            @entries_index[key] = i
          end
      end
    end
  end

  # Get method for entries. Used attribute `key` for indexing.
  # Return first fount Row.
  # @param [Integer, String] key the value that been search
  def get(key)
    index = @entries_index[key.to_i]
    if index
      case index
        when Array
          return @entries.values_at(*index)
        else
          return @entries[index]
      end
    end
    nil
  end

  def method_missing(meth, *args, &block)
    if instance_variable_defined?("@#{meth.to_s}")
      instance_variable_get("@#{meth.to_s}")
    else
      super
    end
  end

  def respond_to?(meth)
    if instance_variable_defined?("@#{meth.to_s}")
      true
    else
      super
    end
  end
end

#entriesObject

The array of Row objects



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/eoat/result/eve_type.rb', line 96

class RowSet
  attr_accessor :key, :columns, :entries, :entries_index

  # @param [Hash] hash the roset value from xml as hash
  def initialize(hash)
    @key = hash['key']
    @columns = hash['columns'].split(',')
    @name = hash['name']
    if hash.key? 'row'
      case hash['row']
        when Array
          @entries = Array.new(hash['row'].map.each {|row| Row.new(row)})
        when Hash
          @entries = Array.new(1, Row.new(hash['row']))
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{hash['row']}"
      end
    else
      @entries = Array.new
    end
    @entries_index = Hash.new
    if @key
      @entries.each_with_index do |record, i|
        key = record.public_send(@key).to_i
          if @entries_index.key? key
            case @entries_index[key]
              when Array
                @entries_index[key] << i
              when Fixnum, Integer
                @entries_index[key] = [@entries_index[key], i]
              else
                # nothing
            end
          else
            @entries_index[key] = i
          end
      end
    end
  end

  # Get method for entries. Used attribute `key` for indexing.
  # Return first fount Row.
  # @param [Integer, String] key the value that been search
  def get(key)
    index = @entries_index[key.to_i]
    if index
      case index
        when Array
          return @entries.values_at(*index)
        else
          return @entries[index]
      end
    end
    nil
  end

  def method_missing(meth, *args, &block)
    if instance_variable_defined?("@#{meth.to_s}")
      instance_variable_get("@#{meth.to_s}")
    else
      super
    end
  end

  def respond_to?(meth)
    if instance_variable_defined?("@#{meth.to_s}")
      true
    else
      super
    end
  end
end

#entries_indexObject

Returns the value of attribute entries_index.



97
98
99
# File 'lib/eoat/result/eve_type.rb', line 97

def entries_index
  @entries_index
end

#keyObject

The value of key for indexing



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/eoat/result/eve_type.rb', line 96

class RowSet
  attr_accessor :key, :columns, :entries, :entries_index

  # @param [Hash] hash the roset value from xml as hash
  def initialize(hash)
    @key = hash['key']
    @columns = hash['columns'].split(',')
    @name = hash['name']
    if hash.key? 'row'
      case hash['row']
        when Array
          @entries = Array.new(hash['row'].map.each {|row| Row.new(row)})
        when Hash
          @entries = Array.new(1, Row.new(hash['row']))
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{hash['row']}"
      end
    else
      @entries = Array.new
    end
    @entries_index = Hash.new
    if @key
      @entries.each_with_index do |record, i|
        key = record.public_send(@key).to_i
          if @entries_index.key? key
            case @entries_index[key]
              when Array
                @entries_index[key] << i
              when Fixnum, Integer
                @entries_index[key] = [@entries_index[key], i]
              else
                # nothing
            end
          else
            @entries_index[key] = i
          end
      end
    end
  end

  # Get method for entries. Used attribute `key` for indexing.
  # Return first fount Row.
  # @param [Integer, String] key the value that been search
  def get(key)
    index = @entries_index[key.to_i]
    if index
      case index
        when Array
          return @entries.values_at(*index)
        else
          return @entries[index]
      end
    end
    nil
  end

  def method_missing(meth, *args, &block)
    if instance_variable_defined?("@#{meth.to_s}")
      instance_variable_get("@#{meth.to_s}")
    else
      super
    end
  end

  def respond_to?(meth)
    if instance_variable_defined?("@#{meth.to_s}")
      true
    else
      super
    end
  end
end

#nameObject (readonly)

The name of rowset



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/eoat/result/eve_type.rb', line 96

class RowSet
  attr_accessor :key, :columns, :entries, :entries_index

  # @param [Hash] hash the roset value from xml as hash
  def initialize(hash)
    @key = hash['key']
    @columns = hash['columns'].split(',')
    @name = hash['name']
    if hash.key? 'row'
      case hash['row']
        when Array
          @entries = Array.new(hash['row'].map.each {|row| Row.new(row)})
        when Hash
          @entries = Array.new(1, Row.new(hash['row']))
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{hash['row']}"
      end
    else
      @entries = Array.new
    end
    @entries_index = Hash.new
    if @key
      @entries.each_with_index do |record, i|
        key = record.public_send(@key).to_i
          if @entries_index.key? key
            case @entries_index[key]
              when Array
                @entries_index[key] << i
              when Fixnum, Integer
                @entries_index[key] = [@entries_index[key], i]
              else
                # nothing
            end
          else
            @entries_index[key] = i
          end
      end
    end
  end

  # Get method for entries. Used attribute `key` for indexing.
  # Return first fount Row.
  # @param [Integer, String] key the value that been search
  def get(key)
    index = @entries_index[key.to_i]
    if index
      case index
        when Array
          return @entries.values_at(*index)
        else
          return @entries[index]
      end
    end
    nil
  end

  def method_missing(meth, *args, &block)
    if instance_variable_defined?("@#{meth.to_s}")
      instance_variable_get("@#{meth.to_s}")
    else
      super
    end
  end

  def respond_to?(meth)
    if instance_variable_defined?("@#{meth.to_s}")
      true
    else
      super
    end
  end
end

Instance Method Details

#get(key) ⇒ Object

Get method for entries. Used attribute key for indexing. Return first fount Row.

Parameters:

  • key (Integer, String)

    the value that been search



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/eoat/result/eve_type.rb', line 139

def get(key)
  index = @entries_index[key.to_i]
  if index
    case index
      when Array
        return @entries.values_at(*index)
      else
        return @entries[index]
    end
  end
  nil
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
# File 'lib/eoat/result/eve_type.rb', line 160

def respond_to?(meth)
  if instance_variable_defined?("@#{meth.to_s}")
    true
  else
    super
  end
end