Class: Posty
- Inherits:
-
Object
- Object
- Posty
- Defined in:
- lib/posty.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(database = nil) ⇒ Posty
constructor
A new instance of Posty.
- #postcode(code) ⇒ Object
Constructor Details
#initialize(database = nil) ⇒ Posty
Returns a new instance of Posty.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/posty.rb', line 21 def initialize database = nil if database.nil? database = Posty.gem_database unless File.exist? database raise IOError, "No database found in gem. Have you run posty-init -g (possibly with sudo)?" end end unless File.exist? database raise IOError, "No database found at #{database}. Have you run posty-init -d '#{database}'?" end @db = SQLite3::Database.new(database) @db.results_as_hash = true end |
Class Method Details
.gem_database ⇒ Object
42 43 44 |
# File 'lib/posty.rb', line 42 def self.gem_database "#{File.dirname(__FILE__)}/posty/codepointopen.sqlite3" end |