buzzcore 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- 0.6.1
1
+ 0.6.2
2
2
 
data/buzzcore.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{buzzcore}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["buzzware"]
12
- s.date = %q{2011-06-03}
12
+ s.date = %q{2011-07-07}
13
13
  s.description = %q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
14
14
  s.email = %q{contact@buzzware.com.au}
15
15
  s.extra_rdoc_files = [
@@ -79,7 +79,31 @@ module DatabaseUtils
79
79
  #end
80
80
 
81
81
 
82
+ # remember to select id column
83
+ def self.process_rows(aTableName,aQuery)
84
+ rows = ActiveRecord::Base.connection.execute(aQuery).all_hashes
85
+ # rows to hash
86
+ rows.each do |r|
87
+ before = r.clone
88
+ yield(r) # modify r
89
+ r[:delete] = true if r == before
90
+ end
91
+ rows.delete_if {|r| r[:delete]}
92
+ rows.each do |r|
93
+ assigns = ''
94
+ r.keys.filter_exclude(['id']).each do |k|
95
+ assigns += ', ' unless assigns.empty?
96
+ assigns += "#{k} = '#{r[k]}'" # should do better escaping here for strings & numbers
97
+ end
98
+ ActiveRecord::Base.connection.execute("update `#{aTableName}` set #{assigns} where id=#{r['id']}")
99
+ end
100
+ end
82
101
 
102
+ def self.process_table(aTableName,aColumns,&block)
103
+ aColumns.map!(&:to_s)
104
+ aColumns << 'id' unless aColumns.include? 'id'
105
+ process_rows(aTableName,"select #{aColumns.join(',')} from `#{aTableName}`",&block)
106
+ end
83
107
 
84
108
  end
85
109
 
@@ -103,14 +103,25 @@ String.class_eval do
103
103
  aDefault
104
104
  end
105
105
 
106
- # uses
107
- #URLIZE_PATTERN = /[ \/\\\(\)\[\]]/
108
- URLIZE_PATTERN_PS = /[ \\\(\)\[\]_]/
109
- def urlize(aSlashChar='+')
106
+ URLIZE_PATTERN_PS = /[ \\\(\)\[\]]/
107
+ URLIZE_EXTENSIONS = %w(html htm jpg jpeg png gif bmp mov avi mp3 zip pdf css js doc xdoc)
108
+
109
+ # aKeepExtensions may be an array of extensions to keep, or :none (will remove periods) or :all (any extension <= 4 chars)
110
+ def urlize(aSlashChar='+',aKeepExtensions=URLIZE_EXTENSIONS)
110
111
  return self if self.empty?
111
- result = self.gsub(URLIZE_PATTERN_PS,'-').downcase.gsub(/[^a-z0-9_\-+,\.\/]/,'').sub(/-+$/,'').sub(/^-+/,'')
112
+ result = self.gsub(URLIZE_PATTERN_PS,'-').downcase
113
+ ext = nil
114
+ if (aKeepExtensions!=:none) && last_dot = result.rindex('.')
115
+ if (ext_len = result.length-last_dot-1) <= 4 # preserve extension without dot if <= 4 chars long
116
+ ext = result[last_dot+1..-1]
117
+ ext = nil unless aKeepExtensions==:all || (aKeepExtensions.is_a?(Array) && aKeepExtensions.include?(ext))
118
+ result = result[0,last_dot] if ext
119
+ end
120
+ end
121
+ result = result.gsub(/[^a-z0-9\_\-+~\/]/,'').sub(/-+$/,'').sub(/^-+/,'')
112
122
  result.gsub!('/',aSlashChar) unless aSlashChar=='/'
113
123
  result.gsub!(/-{2,}/,'-')
124
+ result += '.'+ext if ext
114
125
  result
115
126
  end
116
127
 
@@ -159,6 +170,9 @@ String.class_eval do
159
170
  crc
160
171
  end
161
172
 
173
+ def has_tags?
174
+ index(/<[a-zA-Z\-:0-9]+(\b|>)/) && (index('/>') || index('</')) # contains an opening and closing tag
175
+ end
162
176
 
163
177
  end
164
178
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buzzcore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - buzzware
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-03 00:00:00 +08:00
18
+ date: 2011-07-07 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency