Class: Bookscan::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/bookscan/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#group_urlObject

Returns the value of attribute group_url.



48
49
50
# File 'lib/bookscan/book.rb', line 48

def group_url
  @group_url
end

#titleObject

Returns the value of attribute title.



48
49
50
# File 'lib/bookscan/book.rb', line 48

def title
  @title
end

#urlObject

Returns the value of attribute url.



48
49
50
# File 'lib/bookscan/book.rb', line 48

def url
  @url
end

Instance Method Details

#book_idObject



89
90
91
92
93
94
95
96
97
# File 'lib/bookscan/book.rb', line 89

def book_id
  return isbn if isbn
  title = @title
  if TUNED_PATTERN =~ title
    title = $3
  end
  title.gsub!(/_s\.pdf$/,".pdf")
  Digest::MD5.hexdigest(title).to_s[1,10]
end

#dObject



52
53
54
# File 'lib/bookscan/book.rb', line 52

def d
  return $1 if /.*download.php\?d=([^&]+)/ =~ @url
end

#filenameObject



69
70
71
72
73
74
75
# File 'lib/bookscan/book.rb', line 69

def filename
  return @title if isbn
  if /(.*)\.pdf$/ =~ @title
    return $1 + "_" + book_id + ".pdf"
  end
  raise "Can't make filename"
end

#hashObject



55
56
57
# File 'lib/bookscan/book.rb', line 55

def hash
  return $1 if /.*bookdetail.php\?hash=(.*)/ =~ @group_url
end

#isbnObject



84
85
86
87
# File 'lib/bookscan/book.rb', line 84

def isbn
  return $1 if /_([0-9a-zA-Z]+)_s\.pdf$/ =~ @title
  return $1 if /_([0-9a-zA-Z]+)\.pdf$/ =~ @title
end

#title_shortObject



63
64
65
66
67
# File 'lib/bookscan/book.rb', line 63

def title_short
  @title.sub(/\.pdf$/,"").
    sub(/_s$/,"").
    sub(/_[0-9a-zA-Z]+$/,"")
end

#to_sObject



59
60
61
# File 'lib/bookscan/book.rb', line 59

def to_s
  @title
end

#tune_typeObject



77
78
79
80
81
82
# File 'lib/bookscan/book.rb', line 77

def tune_type
  if TUNED_PATTERN =~ title
    return $2
  end
  nil
end

#tune_urlObject



49
50
51
# File 'lib/bookscan/book.rb', line 49

def tune_url
  "/bookoptimize.php?hash=%s&d=%s&filename=%s" % [hash,d,URI.encode(@title)]
end