Class: CodeStock::SearchContents
- Inherits:
-
Object
- Object
- CodeStock::SearchContents
- Defined in:
- lib/codestock/cdweb/lib/search_contents.rb
Defined Under Namespace
Classes: MatchRecord
Constant Summary collapse
- DISP_NUM =
1ページの表示数
20
- LIMIT_NUM =
最大検索ファイル数
50
- NTH =
表示範囲
3
Instance Attribute Summary collapse
-
#elapsed ⇒ Object
readonly
Returns the value of attribute elapsed.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
- #data_range ⇒ Object
- #html_contents ⇒ Object
- #html_pagination ⇒ Object
-
#initialize(path, params, query) ⇒ SearchContents
constructor
A new instance of SearchContents.
- #next_offset ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(path, params, query) ⇒ SearchContents
Returns a new instance of SearchContents.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 22 def initialize(path, params, query) @params = params @q = query @page = params[:page].to_i || 0 @offset = params[:offset].to_i fpaths = @q.fpaths fpaths << path unless path == "" @records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, LIMIT_NUM) grep_contents end |
Instance Attribute Details
#elapsed ⇒ Object (readonly)
Returns the value of attribute elapsed.
15 16 17 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 15 def elapsed @elapsed end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
16 17 18 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 16 def page @page end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
14 15 16 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 14 def total_records @total_records end |
Instance Method Details
#data_range ⇒ Object
41 42 43 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 41 def data_range @offset..(next_offset - 1) end |
#html_contents ⇒ Object
45 46 47 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 45 def html_contents @match_records.map {|match_record| result_match_record(match_record)}.join end |
#html_pagination ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 49 def html_pagination return "" if @q.empty? return "" if next_offset >= @total_records return <<EOF <div class='pagination'> #{pagination_link(next_offset, "next >>")} </div> EOF end |
#next_offset ⇒ Object
37 38 39 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 37 def next_offset @offset + @next_index end |
#query ⇒ Object
33 34 35 |
# File 'lib/codestock/cdweb/lib/search_contents.rb', line 33 def query @q.query_string end |