Module: Douban::Cite
- Defined in:
- lib/douban/cite.rb,
lib/douban/cite/version.rb
Constant Summary collapse
- Douban_API_base =
'http://api.douban.com'- Douban_Book_info =
Douban_API_base + '/v2/book/'
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.convert_to_ref(book_info, book_type = 'M') ⇒ String
Format: author.
- .get_book_info(id) ⇒ Hash, String
Class Method Details
.convert_to_ref(book_info, book_type = 'M') ⇒ String
Format: author. YYYY-MM. title. other_author. location: publisher. ISBN isbn-number This format is based on:
-
[GB 7714-2005《文后参考文献著录规则》](gradschool.ustc.edu.cn/ylb/material/xw/wdxz/19.pdf)
-
[维基百科:列明来源](zh.wikipedia.org/wiki/Wikipedia:%E5%88%97%E6%98%8E%E6%9D%A5%E6%BA%90)
-
[Harvard referencing](en.wikipedia.org/wiki/Parenthetical_referencing)
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/douban/cite.rb', line 40 def convert_to_ref(book_info, book_type='M') = book_info['author'].join(', ') year_month = book_info['pubdate'] title = book_info['title'] = book_info['translator'].join(', ') publisher = book_info['publisher'] # This is a silly guess. # TODO email douban to complain about this. location = publisher[0..1] isbn = book_info['isbn13'] # `other_author` is handled specially, because often it is not needed. "#{}. #{year_month}. #{title}[#{book_type}]. #{ == '' ? '' : + '. ' }#{location}: #{publisher}. ISBN #{isbn}" end |
.get_book_info(id) ⇒ Hash, String
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/douban/cite.rb', line 18 def get_book_info(id) # Currently douban subject id's length is 7. if StdNum::ISBN.valid?(id) id = 'isbn/' + id end res = RestClient.get(Douban_Book_info + id) if res.code == 200 JSON.parse(res.body) else res.code end end |