class Cinii::SearchResult::Base
Public Class Methods
new(faraday_response)
click to toggle source
# File lib/cinii/search_result/base.rb, line 8 def initialize(faraday_response) @raw_body = faraday_response.body raise APIResponseError, 'レスポンスに@graph属性が含まれていません' unless body['@graph'] end
Public Instance Methods
current_page()
click to toggle source
現在のページ数
# File lib/cinii/search_result/base.rb, line 54 def current_page (start_index.to_f / items_per_page.to_f).ceil end
date()
click to toggle source
検索日時
# File lib/cinii/search_result/base.rb, line 34 def date @date ||= DateTime.parse(graph['dc:date']) end
description()
click to toggle source
タイトルと同じ
# File lib/cinii/search_result/base.rb, line 24 def description @description ||= graph['description'] end
first_page?()
click to toggle source
最初のページ判定
# File lib/cinii/search_result/base.rb, line 64 def first_page? start_index.between?(1, items_per_page) end
items()
click to toggle source
# File lib/cinii/search_result/base.rb, line 14 def items raise 'This method must be overridden.' end
items_per_page()
click to toggle source
検索結果件数
# File lib/cinii/search_result/base.rb, line 49 def items_per_page @items_per_page ||= graph['opensearch:itemsPerPage'].to_i end
last_page?()
click to toggle source
最終ページ判定
# File lib/cinii/search_result/base.rb, line 69 def last_page? start_index.between?(last_page_start_index, total_items) end
last_page_start_index()
click to toggle source
最終ページの開始番号
# File lib/cinii/search_result/base.rb, line 85 def last_page_start_index total_items - items_per_page end
link()
click to toggle source
リクエストURI
# File lib/cinii/search_result/base.rb, line 29 def link @link ||= graph['link']['@id'] end
next_page_start_index()
click to toggle source
次ページの開始番号
# File lib/cinii/search_result/base.rb, line 74 def next_page_start_index start_index + items_per_page end
prev_page_start_index()
click to toggle source
前ページの開始番号
# File lib/cinii/search_result/base.rb, line 79 def prev_page_start_index index = start_index - items_per_page index >= 1 ? index : 1 end
start_index()
click to toggle source
検索結果の開始番号
# File lib/cinii/search_result/base.rb, line 44 def start_index @start_index ||= graph['opensearch:startIndex'].to_i end
title()
click to toggle source
タイトル
# File lib/cinii/search_result/base.rb, line 19 def title @title ||= graph['title'] end
total_items()
click to toggle source
検索結果総数
# File lib/cinii/search_result/base.rb, line 39 def total_items @total_items ||= graph['opensearch:totalResults'].to_i end
total_pages()
click to toggle source
全てのページ数
# File lib/cinii/search_result/base.rb, line 59 def total_pages (total_items.to_f / items_per_page.to_f).ceil end
Private Instance Methods
body()
click to toggle source
# File lib/cinii/search_result/base.rb, line 91 def body @raw_body end
graph()
click to toggle source
# File lib/cinii/search_result/base.rb, line 95 def graph body['@graph'].first end