Class: Zillace::Place

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, url:, title:) ⇒ Place

Returns a new instance of Place.



46
47
48
49
50
# File 'lib/zillace.rb', line 46

def initialize(id:, url:, title:)
  @id = id
  @url = url
  @title = title
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



44
45
46
# File 'lib/zillace.rb', line 44

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



44
45
46
# File 'lib/zillace.rb', line 44

def url
  @url
end

Class Method Details

.each(database: Database.new.connect, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/zillace.rb', line 52

def self.each(database: Database.new.connect, &block)
  enumerator = Enumerator.new do |enumerator|
    database.execute('select id, url, title from moz_places') do |row|
      id, url, title = row
      enumerator << new(id:, url:, title:)
    end
  end

  block_given? ? enumerator.each(&block) : enumerator
end

.find(id, database: Database.new.connect) ⇒ Object



63
64
65
66
# File 'lib/zillace.rb', line 63

def self.find(id, database: Database.new.connect)
  url, title = database.execute('select url, title from moz_places where id = ?', id).first
  return new(id:, url:, title:)
end