orbit-basic/lib/tasks/matt_dev.rake

48 lines
1.4 KiB
Ruby

# encoding: UTF-8
namespace :matt_dev do
desc 'Testing Searching'
task :searching_01 => :environment do
a= Redis::Search.query("Bulletin",'我',:conditions =>{:is_checked=>true,:is_hidden=>false})
p a
a= Redis::Search.query("NewsBulletin",'社科院',:conditions =>{:is_checked=>true,:is_hidden=>false})
p a
# p Pinyin.t('台灣不是中國的一部分')
end
task :testing_new_tag_cal do
ranges = [[1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5],[1,2,3,4,5,6],[1,2,3,4,5,6,7],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10,11],[1,2,3,4,5,6,7,8,9,10,11,12],[-1,-2,-3,-4,5,6,7,8,9,10,11,12]]
ranges.each{ |range|
cal(range)
}
end
def cal(range_t)
range = range_t.sort.reverse
puts '='*20
puts range.to_s
puts '='*20
offset_size = range.size+4
section_3 = range.last..range[-(offset_size/4)]
puts(section_3)
section_2 = range[-(offset_size/4)-1]..range[-2*(offset_size/4)] rescue nil
puts(section_2)
section_1 = range[-2*(offset_size/4)-1]..range[1] rescue nil
puts(section_1)
range.each{|num|
result= case num
when range.first
:heading1
when section_1
:heading2
when section_2
:heading3
when section_3
:heading4
end
puts "Num:#{num} Result: #{result}"
}
puts("END")
end
end