Class: Milkode::SearchFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/cdweb/lib/search_files.rb

Constant Summary collapse

DISP_NUM =

1ページの表示数

100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, params, query) ⇒ SearchFiles

Returns a new instance of SearchFiles.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/milkode/cdweb/lib/search_files.rb', line 19

def initialize(path, params, query)
  @path = path
  @params = params
  @q = query
  
  @offset = params[:offset].to_i

  if (@q.fpaths.include?("*"))
    @records, @total_records = Database.instance.selectAll(@offset, DISP_NUM)
  else
    @records, @total_records = Database.instance.search(@q.keywords, @q.packages, path, @q.fpaths, @q.suffixs, @offset, DISP_NUM)
  end
end

Instance Attribute Details

#total_recordsObject (readonly)

Returns the value of attribute total_records.



15
16
17
# File 'lib/milkode/cdweb/lib/search_files.rb', line 15

def total_records
  @total_records
end

Instance Method Details

#data_rangeObject



41
42
43
# File 'lib/milkode/cdweb/lib/search_files.rb', line 41

def data_range
  @offset..(next_offset - 1)
end

#html_contentsObject



45
46
47
# File 'lib/milkode/cdweb/lib/search_files.rb', line 45

def html_contents
  @records.map {|record| result_record(record)}.join
end

#html_paginationObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/milkode/cdweb/lib/search_files.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

#match_numObject



60
61
62
# File 'lib/milkode/cdweb/lib/search_files.rb', line 60

def match_num
  @records.size
end

#next_offsetObject



37
38
39
# File 'lib/milkode/cdweb/lib/search_files.rb', line 37

def next_offset
  @offset + @records.size
end

#queryObject



33
34
35
# File 'lib/milkode/cdweb/lib/search_files.rb', line 33

def query
  @q.query_string
end