earthquake 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.6.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{earthquake}
8
- s.version = "0.6.7"
8
+ s.version = "0.6.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
@@ -43,6 +43,14 @@ class String
43
43
  "\e[#{codes.join(';')}m#{self}\e[0m"
44
44
  end
45
45
 
46
+ def coloring(pattern, color = nil, &block)
47
+ self.gsub(pattern) do |i|
48
+ applied_colors = self[0...$~.begin(0)].scan(/\e\[[\d;]+m/)
49
+ color ||= block.call(i)
50
+ "#{i.c(color)}#{applied_colors.join}"
51
+ end
52
+ end
53
+
46
54
  def u
47
55
  gsub(/&(lt|gt|amp|quot|apos);/) do |s|
48
56
  case s
@@ -92,26 +92,14 @@ module Earthquake
92
92
 
93
93
  text = item["text"].u
94
94
  text.gsub!(/\s+/, ' ') unless config[:raw_text]
95
- text.gsub!(/@([0-9A-Za-z_]+)/) do |i|
96
- i.c(color_of($1))
97
- end
98
- text.gsub!(/(?:^#([^\s]+))|(?:\s+#([^\s]+))/) do |i|
99
- i.c(color_of($1 || $2))
100
- end
101
- text.gsub!(URI.regexp(["http", "https"])) do |i|
102
- i.c(:url)
103
- end
95
+ text = text.coloring(/@([0-9A-Za-z_]+)/) { |i| color_of(i) }
96
+ text = text.coloring(/(?:^#([^\s]+))|(?:\s+#([^\s]+))/) { |i| color_of(i) }
97
+ text = text.coloring(URI.regexp(["http", "https"]), :url)
104
98
 
105
99
  if item["_highlights"]
106
100
  item["_highlights"].each do |h|
107
- if config[:color][:highlight].nil?
108
- c = color_of(h).to_i + 10
109
- else
110
- c = :highlight
111
- end
112
- text = text.gsub(/#{h}/i) do |i|
113
- i.c(c)
114
- end
101
+ color = config[:color][:highlight].nil? ? color_of(h).to_i + 10 : :highlight
102
+ text = text.coloring(/#{h}/i, color)
115
103
  end
116
104
  end
117
105
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earthquake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.7
5
+ version: 0.6.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo