Class: Kanshi::Collector
- Inherits:
-
Object
- Object
- Kanshi::Collector
- Defined in:
- lib/kanshi/collector.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collect ⇒ Object
-
#initialize(database_url) ⇒ Collector
constructor
A new instance of Collector.
- #with_db(&block) ⇒ Object
Constructor Details
#initialize(database_url) ⇒ Collector
Returns a new instance of Collector.
10 11 12 13 |
# File 'lib/kanshi/collector.rb', line 10 def initialize(database_url) @url = database_url @db_name = URI.parse(@url).path[1..-1] end |
Class Method Details
.collect(*args) ⇒ Object
6 7 8 |
# File 'lib/kanshi/collector.rb', line 6 def self.collect(*args) new(*args).collect end |
Instance Method Details
#collect ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/kanshi/collector.rb', line 22 def collect data = {} with_db do |db| ::Kanshi::Queries.each do |query| data.merge! db[query, @db_name].first end end data end |
#with_db(&block) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/kanshi/collector.rb', line 15 def with_db(&block) db = Sequel.connect(@url) yield db ensure db.disconnect if db end |