Class: Croque::Monsieur
- Inherits:
-
Object
- Object
- Croque::Monsieur
- Defined in:
- lib/croque/monsieur.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#id ⇒ Object
Returns the value of attribute id.
-
#line ⇒ Object
Returns the value of attribute line.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #active_record_time ⇒ Object
- #body ⇒ Object
- #full_path ⇒ Object
-
#initialize(date, hour, id, time) ⇒ Monsieur
constructor
A new instance of Monsieur.
- #path_info ⇒ Object
- #processing_time ⇒ Object
- #query ⇒ Object
- #views_time ⇒ Object
Constructor Details
#initialize(date, hour, id, time) ⇒ Monsieur
Returns a new instance of Monsieur.
6 7 8 9 10 11 |
# File 'lib/croque/monsieur.rb', line 6 def initialize(date, hour, id, time) self.date = Date.parse(date) self.hour = hour.to_i self.id = id self.time = time end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/croque/monsieur.rb', line 4 def date @date end |
#hour ⇒ Object
Returns the value of attribute hour.
4 5 6 |
# File 'lib/croque/monsieur.rb', line 4 def hour @hour end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/croque/monsieur.rb', line 4 def id @id end |
#line ⇒ Object
Returns the value of attribute line.
4 5 6 |
# File 'lib/croque/monsieur.rb', line 4 def line @line end |
#time ⇒ Object
Returns the value of attribute time.
4 5 6 |
# File 'lib/croque/monsieur.rb', line 4 def time @time end |
Class Method Details
.get_list(date, page, per) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/croque/monsieur.rb', line 46 def get_list(date, page, per) # maybe String page_num = (page || 1).to_i per_num = (per || total_count(date)).to_i # get csv data csv_data = File.open(ranking_path(date), "r").read.gsub(/\r/, "") csv = CSV.new(csv_data) # Sorted lines as ranking start = ((page_num-1)*per_num) # csv to Array lines = csv.to_a # start..end lines = lines.slice(start, per_num) || [] # generate this class instance lines.map do |line| # line = [date, hour, uuid, processing_time (ms)] self.new(*line) end end |
.total_count(date) ⇒ Object
66 67 68 69 |
# File 'lib/croque/monsieur.rb', line 66 def total_count(date) wc_result = `wc -l #{ranking_path(date)}` wc_result.match(/\d+/)[0].try(:to_i) end |
Instance Method Details
#active_record_time ⇒ Object
25 26 27 |
# File 'lib/croque/monsieur.rb', line 25 def active_record_time get_line[3].to_f end |
#body ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/croque/monsieur.rb', line 13 def body # return Array lines = get_line[7].split("\t") lines.map do |line| line.strip.gsub(/\e\[\d+m/, '') end end |
#full_path ⇒ Object
33 34 35 |
# File 'lib/croque/monsieur.rb', line 33 def full_path URI.unescape(get_line[4]) end |
#path_info ⇒ Object
37 38 39 |
# File 'lib/croque/monsieur.rb', line 37 def path_info get_line[5] end |
#processing_time ⇒ Object
29 30 31 |
# File 'lib/croque/monsieur.rb', line 29 def processing_time self.time.to_f end |
#query ⇒ Object
41 42 43 |
# File 'lib/croque/monsieur.rb', line 41 def query URI.unescape(get_line[6]) end |
#views_time ⇒ Object
21 22 23 |
# File 'lib/croque/monsieur.rb', line 21 def views_time get_line[2].to_f end |