Class: Kindai::Book
- Inherits:
-
Object
- Object
- Kindai::Book
- Defined in:
- lib/kindai/book.rb
Class Method Summary collapse
- .new_from_local_directory(path) ⇒ Object
-
.new_from_permalink(permalink_uri) ⇒ Object
—– constructor —–.
Instance Method Summary collapse
- #alt_author ⇒ Object
- #author ⇒ Object
- #key ⇒ Object
-
#permalink_uri ⇒ Object
—– metadata —–.
- #spreads ⇒ Object
- #title ⇒ Object
- #total_spread ⇒ Object
Class Method Details
.new_from_local_directory(path) ⇒ Object
15 16 17 18 19 |
# File 'lib/kindai/book.rb', line 15 def self.new_from_local_directory(path) = File.join(path, 'metadata') permalink = open().read.chomp return self.new_from_permalink(permalink) end |
.new_from_permalink(permalink_uri) ⇒ Object
—– constructor —–
6 7 8 9 10 11 12 13 |
# File 'lib/kindai/book.rb', line 6 def self.new_from_permalink(permalink_uri) raise "not info:ndljp: #{permalink_uri}" unless permalink_uri.match(/info\:ndljp/) me = new me.instance_eval { @permalink_uri = permalink_uri } return me end |
Instance Method Details
#alt_author ⇒ Object
44 45 46 47 48 |
# File 'lib/kindai/book.rb', line 44 def 'creator' rescue 'publisher' end |
#author ⇒ Object
38 39 40 41 42 |
# File 'lib/kindai/book.rb', line 38 def 'creator:NDLNH' rescue end |
#key ⇒ Object
27 28 29 |
# File 'lib/kindai/book.rb', line 27 def key permalink_uri.match(/\d+$/)[0] end |
#permalink_uri ⇒ Object
—– metadata —–
23 24 25 |
# File 'lib/kindai/book.rb', line 23 def permalink_uri @permalink_uri end |
#spreads ⇒ Object
54 55 56 |
# File 'lib/kindai/book.rb', line 54 def spreads @spreads ||= 1.upto(self.total_spread).map{|i| self.spread_at(i) } end |
#title ⇒ Object
31 32 33 34 35 36 |
# File 'lib/kindai/book.rb', line 31 def title main = 'title' sub = ('volumeTranscription').to_i.to_s rescue nil sub ? main + sub : main end |
#total_spread ⇒ Object
50 51 52 |
# File 'lib/kindai/book.rb', line 50 def total_spread permalink_page.search('#sel-content-no option').length end |