Class: Txdb::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/txdb/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, options = {}) ⇒ Table

Returns a new instance of Table.



9
10
11
12
13
14
# File 'lib/txdb/table.rb', line 9

def initialize(database, options = {})
  @database = database
  @name = options.fetch(:name)
  @columns = options.fetch(:columns)
  @source_lang = options.fetch(:source_lang)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/txdb/table.rb', line 6

def columns
  @columns
end

#databaseObject (readonly)

Returns the value of attribute database.



6
7
8
# File 'lib/txdb/table.rb', line 6

def database
  @database
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/txdb/table.rb', line 6

def name
  @name
end

#source_langObject (readonly)

Returns the value of attribute source_lang.



7
8
9
# File 'lib/txdb/table.rb', line 7

def source_lang
  @source_lang
end

Instance Method Details

#dbObject



16
17
18
# File 'lib/txdb/table.rb', line 16

def db
  database.db.from(name)
end

#read_contentObject



24
25
26
27
28
# File 'lib/txdb/table.rb', line 24

def read_content
  YAML.dump(
    database.backend.read_content_from(self)
  )
end

#resourceObject



20
21
22
# File 'lib/txdb/table.rb', line 20

def resource
  @resource ||= Txdb::TxResource.from_table(self)
end

#write_content(content, locale) ⇒ Object



30
31
32
33
34
# File 'lib/txdb/table.rb', line 30

def write_content(content, locale)
  database.backend.write_content_to(
    self, YAML.load(content), locale
  )
end