ruby_extensions 1.0.8 → 1.0.11

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/lib/m_logger.rb CHANGED
@@ -1,55 +0,0 @@
1
- class Logger
2
-
3
- %W[error debug fatal info warn].each do |level|
4
- class_eval %{
5
- alias_method :old_#{level}, :#{level}
6
-
7
- def #{level}(progname = nil, &block)
8
- old_#{level}(format_progname(progname), &block)
9
- end
10
- }
11
- end
12
-
13
- j = 5
14
- 5.times do |i|
15
- lbs = ""
16
- ast = ""
17
- j.times { lbs << "\n"}
18
- (j * 5).times { ast << "*"}
19
- class_eval %{
20
- def debug_#{i+1}(progname = nil, &block)
21
- progname = format_progname(progname)
22
- mess = "\n#{ast}#{lbs}\#{progname}#{lbs}#{ast}"
23
- debug(mess, &block)
24
- end
25
- }
26
- j = j - 1
27
- end
28
-
29
- def format_message(severity, timestamp, progname, msg)
30
- # Check for characters at the start of the message string indicating special formatting
31
- # Make the typical case as efficient as possible
32
- if not msg[0..1] == '$@'
33
- pid = (defined?(ENABLE_PIDS_IN_LOGS) and ENABLE_PIDS_IN_LOGS) ? "(#{$$}) " : ''
34
- return "#{pid}[#{severity}]\t#{timestamp}\t#{msg}\n"
35
- end
36
- format = msg[2..2]
37
- msg = msg[3..-1]
38
- # Original format
39
- if format == 'O'
40
- return "#{timestamp}\t[#{severity}]\t#{msg}\n"
41
- elsif format == 'S'
42
- return "#{msg}\n"
43
- end
44
-
45
- end
46
-
47
- private
48
- def format_progname(progname)
49
- unless progname.nil?
50
- progname = "#{progname.to_s}\n#{progname.backtrace.join("\n\t")}\n" if progname.is_a? Exception
51
- end
52
- progname
53
- end
54
-
55
- end
data/lib/m_object.rb CHANGED
@@ -10,7 +10,12 @@ class Object
10
10
  e = "---Ending at #{e_time}---"
11
11
  puts e
12
12
  logger.info e unless logger.nil?
13
- x = "Running time #{e_time - s_time} seconds."
13
+ secs = e_time - s_time
14
+ if secs < 60
15
+ x = "Running time #{secs} seconds."
16
+ else
17
+ x = "Running time roughly #{secs/60} minutes [#{secs} seconds]"
18
+ end
14
19
  x += " [MESSAGE]: #{message}" unless message.blank?
15
20
  puts x
16
21
  logger.info x unless logger.nil?
data/lib/m_string.rb CHANGED
@@ -1,13 +1,22 @@
1
+ require 'digest'
1
2
  class String
2
3
 
3
4
  def linkify(enabled = true, options = {}, &block)
4
5
  text = self.dup
5
- m = text.match(/(\".*?\":\S*)/)
6
+ m = text.match(/\"([^"]+)\"\:([^:]+\:\S+)/)
6
7
  until m.nil?
7
- y = m.to_s.strip
8
- t = y.match(/\"(.*)\"/).captures
9
- url = y.match(/\":(.*)/).captures
10
- break if t.to_s == "" or url.to_s == ""
8
+ y = m.to_s
9
+ t = m[1]
10
+ url = m[2]
11
+
12
+ # The code below handles punctuation or p tags being mistakenly added to the url when the link is at the end of a sentence or body
13
+ url_punct_match = /\W*[&nbsp;]*[\<\/p\>]*$/.match(url)
14
+ punct = ''
15
+ if url_punct_match && url_punct_match[0] != ""
16
+ url.chomp!(url_punct_match[0])
17
+ punct = url_punct_match[0] unless url_punct_match == "="
18
+ end
19
+
11
20
  if block_given?
12
21
  if enabled
13
22
  ret = yield t, url, options
@@ -17,12 +26,12 @@ class String
17
26
  end
18
27
  else
19
28
  if enabled
20
- text.gsub!(y, "<a href=\"#{url}\" #{options.join("%s=\"%s\"", " ")}>#{t}</a>")
29
+ text.gsub!(y, "<a href=\"#{url}\" #{options.join("%s=\"%s\"", " ")}>#{t}</a>#{punct}")# punct places punctuation back into proper place
21
30
  else
22
31
  text.gsub!(y, t.to_s)
23
32
  end
24
33
  end
25
- m = text.match(/\s(\".*?\":\S*)/)
34
+ m = text.match(/\"([^"]+)\"\:([^:]+\:\S+)/)
26
35
  end
27
36
  return text
28
37
  end
@@ -139,7 +148,22 @@ class String
139
148
  def breakify(every = 30)
140
149
  every = 1 if every < 1
141
150
  text = self
142
- brokentxt = text.gsub(/\S{#{every},}/) { |longword| longword.scan(/.{1,#{every}}/).join("<wbr/>") }
151
+ textile_regex = /\"([^\"]+)\":([^:]*:[\/\/]{0,1}[^ ]*)/
152
+ long_regex = /\S{#{every},}/
153
+ brokentxt = text.gsub(long_regex) do |longword|
154
+ if longword =~ textile_regex #if the longword is a textile link...ignore and recheck for the link text only
155
+ textile_link = textile_regex.match(longword)[0]
156
+ link_text = textile_regex.match(longword)[1]
157
+ longword = link_text
158
+ if longword =~ long_regex #link text is long...allow break
159
+ textile_link.scan(/.{1,#{every}}/).join("<wbr/>")
160
+ else
161
+ textile_link #the url is what triggered the match...so leave it alone
162
+ end
163
+ else
164
+ longword.scan(/.{1,#{every}}/).join("<wbr/>") #no textile link matched
165
+ end
166
+ end
143
167
  #text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]
144
168
  #brokentxt.gsub("<wbr/>", "<br />")
145
169
  brokentxt.gsub("<wbr/>", " ")
@@ -2,4 +2,4 @@
2
2
  gem_name: ruby_extensions
3
3
  package: ruby_extensions
4
4
  project: magrathea
5
- version: 1.0.8
5
+ version: 1.0.11
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -35,7 +35,7 @@ autorequire:
35
35
  bindir: bin
36
36
  cert_chain: []
37
37
 
38
- date: 2008-01-29 00:00:00 -05:00
38
+ date: 2008-02-27 00:00:00 -05:00
39
39
  default_executable:
40
40
  dependencies: []
41
41