Class: String

Inherits:
Object show all
Defined in:
lib/http_crawler/common/string.rb

Instance Method Summary collapse

Instance Method Details

#jagger_del_inter ⇒ Object

清除干扰数据 清除包含: 空格,回车



5
6
7
# File 'lib/http_crawler/common/string.rb', line 5

def jagger_del_inter
  self.gsub(/(?:\n|\t|\r| | )/, "")
end

#jagger_to_time ⇒ Object

转换成时间格式



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/http_crawler/common/string.rb', line 10

def jagger_to_time

  # 然后先遍历所有格式
  [
      "%Y年%m月%d日%H:%M:%S",
      "%Y年%m月%d日 %H:%M:%S",
      "%Y年%m月%d日%H:%M",
      "%Y年%m月%d日 %H:%M",

      "%Y-%m-%d%H:%M:%S",
      "%Y-%m-%d %H:%M:%S",
      "%Y-%m-%d%H:%M",
      "%Y-%m-%d %H:%M",

      "%Y-%m-%d",
      "%Y年%m月%d日",
      "%Y%m%d",

      "%m月%d日",

      "%m月%d日 %H%M",
      "%m月%d日 %H%M%S",
      "%m月%d日%H%M",
      "%m月%d日%H%M%S",

      "%m月%d日 %H:%M",
      "%m月%d日 %H:%M:%S",
      "%m月%d日%H:%M",
      "%m月%d日%H:%M:%S",

      "%Y%m%d%H%M%S",
      "%Y%m%d%H%M",

  ].each do |v|
    Rails.logger.debug v
    begin
      return Time.strptime(self, v)
    rescue => error

    end
  end

  return Time.at(self.to_i / 1000.0) if self.length == 13
  return Time.at(self.to_i) if self.length == 10

  # 最后用 Time通用类型尝试
  return Time.parse(self)
end