Class: BomDB::Models::Edition
- Inherits:
-
Object
- Object
- BomDB::Models::Edition
- Defined in:
- lib/bomdb/models/edition.rb
Instance Method Summary collapse
-
#find(edition_name_prefix) ⇒ Object
Find an edition and return a hash, or nil if not found.
-
#find_or_create(year, name) ⇒ Object
Returns an edition_id, either found in the db, or created as necessary.
-
#initialize(db) ⇒ Edition
constructor
A new instance of Edition.
Constructor Details
#initialize(db) ⇒ Edition
Returns a new instance of Edition.
4 5 6 |
# File 'lib/bomdb/models/edition.rb', line 4 def initialize(db) @db = db end |
Instance Method Details
#find(edition_name_prefix) ⇒ Object
Find an edition and return a hash, or nil if not found
9 10 11 12 13 14 |
# File 'lib/bomdb/models/edition.rb', line 9 def find(edition_name_prefix) @db[:editions]. where(Sequel.like(:edition_name, "#{edition_name_prefix}%")). or(:edition_year => edition_name_prefix). first end |
#find_or_create(year, name) ⇒ Object
Returns an edition_id, either found in the db, or created as necessary
17 18 19 20 21 22 23 24 |
# File 'lib/bomdb/models/edition.rb', line 17 def find_or_create(year, name) found = @db[:editions].where(edition_year: year, edition_name: name).first return found[:edition_id] if found @db[:editions].insert( edition_year: year, edition_name: name ) end |