Add language to book data.
authorChris Jaekl <chris@localhost>
Sun, 29 Mar 2020 19:07:46 +0000 (15:07 -0400)
committerChris Jaekl <chris@localhost>
Sun, 29 Mar 2020 19:07:46 +0000 (15:07 -0400)
book.rb
store.rb

diff --git a/book.rb b/book.rb
index 93c3964d4a88939a9e1019cd1a5585411cb47404..d7135690d4d60514f4c900d59dc76698d3eb164d 100644 (file)
--- a/book.rb
+++ b/book.rb
@@ -15,6 +15,7 @@ class Book
   attr_accessor :classification_id
   attr_accessor :cover
   attr_accessor :description
+  attr_accessor :language
   attr_accessor :path
   attr_accessor :series_id
   attr_accessor :title
@@ -308,6 +309,17 @@ class Book
       end
     end
 
+    #---------------------------------------
+    # Language
+
+    langNodes = opfDoc.css('dc|language', 'dc' => @@DC_NS_URL)
+    if (langNodes.length > 0)
+      langNode = langNodes[0]
+      if langNode
+        @language = langNode.content
+      end
+    end
+
     #---------------------------------------
     # Other metadata:  series, volume, cover
 
index 7494b8d93dc849074091c6a1953622e772a12359..5faf7ce884c21371a58ea3dbafec2cece7899a0a 100644 (file)
--- a/store.rb
+++ b/store.rb
@@ -66,6 +66,7 @@ EOS
         author         INTEGER REFERENCES Authors(id),
         classification INTEGER REFERENCES Classifications(id),
         cover          INTEGER,
+        language       VARCHAR(64),
         description    TEXT,
         path           VARCHAR(256),
         series         INTEGER REFERENCES Series(id),
@@ -235,7 +236,7 @@ EOS
   end
 
   def load_book(id)
-    sql = "SELECT author, classification, cover, description, path, series, title, volume FROM Books WHERE id=$1;"
+    sql = "SELECT author, classification, cover, description, language, path, series, title, volume FROM Books WHERE id=$1;"
     book = nil
 
     begin
@@ -251,6 +252,7 @@ EOS
         book.classification_id = row['classification']
         book.cover = load_cover(row['cover'])
         book.description = row['description']
+        book.language = row['language']
         book.path = row['path']
         book.series_id = row['series']
         book.title = row['title']
@@ -266,14 +268,14 @@ EOS
   end
 
   def store_book(book)
-    sql = "INSERT INTO Books (id, author, classification, cover, description, path, series, title, volume) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);"
+    sql = "INSERT INTO Books (id, author, classification, cover, description, language, path, series, title, volume) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"
 
     book_id = next_id('book_id')
 
     author_id = store_author(book.author)
     (efs_id, mime_type) = store_cover(book)
 
-    args = [book_id, author_id, book.classification_id, efs_id, book.description(), book.path(), book.series_id(), book.title(), book.volume()]
+    args = [book_id, author_id, book.classification_id, efs_id, book.description, book.language, book.path, book.series_id, book.title, book.volume]
 
     begin
       rs = @conn.exec_params(sql, args)