Class: Droonga::Catalog::Schema::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/catalog/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data) ⇒ Table

Returns a new instance of Table.



143
144
145
146
147
148
149
150
151
# File 'lib/droonga/catalog/schema.rb', line 143

def initialize(name, data)
  @name = name
  @data = data
  @columns = {}

  columns_data.each do |column_name, column_data|
    @columns[column_name] = Column.new(name, column_name, column_data)
  end
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



142
143
144
# File 'lib/droonga/catalog/schema.rb', line 142

def columns
  @columns
end

#dataObject (readonly)

Returns the value of attribute data.



142
143
144
# File 'lib/droonga/catalog/schema.rb', line 142

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



142
143
144
# File 'lib/droonga/catalog/schema.rb', line 142

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



153
154
155
156
157
# File 'lib/droonga/catalog/schema.rb', line 153

def ==(other)
  self.class == other.class and
    name == other.name and
    data == other.data
end

#flagsObject



201
202
203
# File 'lib/droonga/catalog/schema.rb', line 201

def flags
  [type_flag]
end

#key_typeObject



163
164
165
# File 'lib/droonga/catalog/schema.rb', line 163

def key_type
  @data["keyType"]
end

#key_type_groongaObject



167
168
169
170
171
172
173
174
175
176
# File 'lib/droonga/catalog/schema.rb', line 167

def key_type_groonga
  case key_type
  when "Integer"
    "Int64"
  when "Float", "Time", "ShortText", "TokyoGeoPoint", "WGS84GeoPoint"
    key_type
  else
    # TODO raise appropriate error
  end
end

#normalizerObject



182
183
184
# File 'lib/droonga/catalog/schema.rb', line 182

def normalizer
  @data["normalizer"]
end

#to_table_create_bodyObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/droonga/catalog/schema.rb', line 205

def to_table_create_body
  body = {
    "name"     => name,
    "key_type" => key_type_groonga,
    "flags"    => flags.join("|")
  }

  if tokenizer
    body["default_tokenizer"] = tokenizer
  end

  if normalizer
    body["normalizer"] = normalizer
  end

  body
end

#tokenizerObject



178
179
180
# File 'lib/droonga/catalog/schema.rb', line 178

def tokenizer
  @data["tokenizer"]
end

#typeObject



159
160
161
# File 'lib/droonga/catalog/schema.rb', line 159

def type
  @data["type"] || "Hash"
end

#type_flagObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/droonga/catalog/schema.rb', line 186

def type_flag
  case type
  when "Array"
    "TABLE_NO_KEY"
  when "Hash"
    "TABLE_HASH_KEY"
  when "PatriciaTrie"
    "TABLE_PAT_KEY"
  when "DoubleArrayTrie"
    "TABLE_DAT_KEY"
  else
    # TODO raise appropriate error
  end
end