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
- #edition ⇒ Object
- #key ⇒ Object
-
#permalink_uri ⇒ Object
—– metadata —–.
- #spreads ⇒ Object
- #title ⇒ Object
- #total_spread ⇒ Object
- #volume_number ⇒ 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
69 70 71 72 73 |
# File 'lib/kindai/book.rb', line 69 def 'creator' rescue 'publisher' end |
#author ⇒ Object
63 64 65 66 67 |
# File 'lib/kindai/book.rb', line 63 def 'creator:NDLNH' rescue end |
#edition ⇒ Object
57 58 59 60 61 |
# File 'lib/kindai/book.rb', line 57 def edition return ('edition') rescue nil 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
79 80 81 |
# File 'lib/kindai/book.rb', line 79 def spreads @spreads ||= 1.upto(self.total_spread).map{|i| self.spread_at(i) } end |
#title ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/kindai/book.rb', line 31 def title base = "#{ 'title'}#{volume_number}" if edition base += "(#{edition})" end base end |
#total_spread ⇒ Object
75 76 77 |
# File 'lib/kindai/book.rb', line 75 def total_spread permalink_page.search('#sel-content-no option').length end |
#volume_number ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kindai/book.rb', line 41 def volume_number # 0036 とか begin return ('volumeTranscription').to_i rescue end # 第36巻 とか begin return ('volume').scan(/\d+/).first.to_i rescue end nil end |