Class: EOAT::Result::EveType::RowSet
- Inherits:
-
Object
- Object
- EOAT::Result::EveType::RowSet
- Defined in:
- lib/eoat/result/eve_type.rb
Overview
Rowset container for xml data. Usually not called directly
Instance Attribute Summary collapse
-
#columns ⇒ Object
The array of methods names for Row class.
-
#entries ⇒ Object
The array of Row objects.
-
#entries_index ⇒ Object
Returns the value of attribute entries_index.
-
#key ⇒ Object
The value of key for indexing.
-
#name ⇒ Object
readonly
The name of rowset.
Instance Method Summary collapse
-
#get(key) ⇒ Object
Get method for entries.
-
#initialize(hash) ⇒ RowSet
constructor
A new instance of RowSet.
- #method_missing(meth, *args, &block) ⇒ Object
- #respond_to?(meth) ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ RowSet
Returns a new instance of RowSet.
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
#columns ⇒ Object
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 |
#entries ⇒ Object
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_index ⇒ Object
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 |
#key ⇒ Object
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 |
#name ⇒ Object (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.
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
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 |