Class: Txdb::Downloader
- Inherits:
-
Object
- Object
- Txdb::Downloader
- Defined in:
- lib/txdb/downloader.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Class Method Summary collapse
Instance Method Summary collapse
- #download(locale) ⇒ Object
- #download_all ⇒ Object
- #download_resource(tx_resource, table, locale) ⇒ Object
- #download_table(table, locale) ⇒ Object
-
#initialize(database) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(database) ⇒ Downloader
Returns a new instance of Downloader.
17 18 19 |
# File 'lib/txdb/downloader.rb', line 17 def initialize(database) @database = database end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
15 16 17 |
# File 'lib/txdb/downloader.rb', line 15 def database @database end |
Class Method Details
.download(database, locale) ⇒ Object
6 7 8 |
# File 'lib/txdb/downloader.rb', line 6 def download(database, locale) new(database).download(locale) end |
.download_all(database) ⇒ Object
10 11 12 |
# File 'lib/txdb/downloader.rb', line 10 def download_all(database) new(database).download_all end |
Instance Method Details
#download(locale) ⇒ Object
30 31 32 33 34 |
# File 'lib/txdb/downloader.rb', line 30 def download(locale) database.tables.each do |table| download_table(table, locale) end end |
#download_all ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/txdb/downloader.rb', line 21 def download_all database.tables.each do |table| database.locales.each do |locale| next if locale == database.source_locale download_table(table, locale) end end end |
#download_resource(tx_resource, table, locale) ⇒ Object
43 44 45 46 47 |
# File 'lib/txdb/downloader.rb', line 43 def download_resource(tx_resource, table, locale) content = transifex_api.download(tx_resource, locale) resource = Txdb::TxResource.new(tx_resource, content) table.write_content(resource, locale) end |
#download_table(table, locale) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/txdb/downloader.rb', line 36 def download_table(table, locale) resources.each do |tx_resource| next unless process_resource?(tx_resource, table) download_resource(tx_resource, table, locale) end end |