mark_facets 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mark_facets/ruby/string.rb +91 -0
  2. metadata +5 -5
@@ -23,6 +23,97 @@ class String
23
23
 
24
24
  alias_method :to_boolean, :to_bool
25
25
 
26
+ def methodize
27
+ m = self.dup
28
+ m.strip!
29
+ m.match(/([\?\=\!])$/)
30
+ punc = $1
31
+ m = m.underscore if m.respond_to?(:underscore)
32
+ m.downcase!
33
+ m = m[0..100] if m.length > 100
34
+ m.gsub!(/(\W)/, '_')
35
+ m.gsub!(/_+$/, '')
36
+ m.gsub!(/^[^a-z]+/, '')
37
+ [' ', '_', '?', '!', "="].each do |c|
38
+ m.squeeze!(c)
39
+ end
40
+ raise NameError.new("#{self} cannot be converted to a valid method name!") if m.nil? || m == ''
41
+ return "#{m}#{punc}"
42
+ end
43
+
44
+ # def methodize
45
+ # x = self
46
+ #
47
+ # # if we get down to a nil or an empty string raise an exception!
48
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
49
+ #
50
+ # # get rid of the big stuff in the front/back
51
+ # x.strip!
52
+ #
53
+ # # if we get down to a nil or an empty string raise an exception!
54
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
55
+ #
56
+ # x = x.underscore
57
+ #
58
+ # # get rid of spaces and make the _
59
+ # x.gsub!(' ', '_')
60
+ # # get rid of everything that isn't 'safe' a-z, 0-9, ?, !, =, _
61
+ # x.gsub!(/([^ a-zA-Z0-9\_\?\!\=]+)/n, '_')
62
+ #
63
+ # # if we get down to a nil or an empty string raise an exception!
64
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
65
+ #
66
+ # # condense multiple 'safe' non a-z chars to just one.
67
+ # # ie. ___ becomes _ !!!! becomes ! etc...
68
+ # [' ', '_', '?', '!', "="].each do |c|
69
+ # x.squeeze!(c)
70
+ # end
71
+ #
72
+ # # if we get down to a nil or an empty string raise an exception!
73
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
74
+ #
75
+ # #down case the whole thing
76
+ # x.downcase!
77
+ #
78
+ # # get rid of any characters at the beginning that aren't a-z
79
+ # while !x.match(/^[a-z]/)
80
+ # x.slice!(0)
81
+ #
82
+ # # if we get down to a nil or an empty string raise an exception!
83
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
84
+ # end
85
+ #
86
+ # # let's trim this bad boy down a bit now that we've cleaned it up, somewhat.
87
+ # # we should do this before cleaning up the end character, because it's possible to end up with a
88
+ # # bad char at the end if you trim too late.
89
+ # x = x[0..100] if x.length > 100
90
+ #
91
+ # # get rid of any characters at the end that aren't safe
92
+ # while !x.match(/[a-z0-9\?\!\=]$/)
93
+ # x.slice!(x.length - 1)
94
+ # # if we get down to a nil or an empty string raise an exception!
95
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
96
+ # end
97
+ #
98
+ # # if we get down to a nil or an empty string raise an exception!
99
+ # raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
100
+ #
101
+ # # let's get rid of characters that don't belong in the 'middle' of the method.
102
+ # orig_middle = x[1..(x.length - 2)]
103
+ # n_middle = orig_middle.dup
104
+ #
105
+ # ['?', '!', "="].each do |c|
106
+ # n_middle.gsub!(c, "_")
107
+ # end
108
+ #
109
+ # # the previous gsub can leave us with multiple underscores that need cleaning up.
110
+ # n_middle.squeeze!("_")
111
+ #
112
+ # x.gsub!(orig_middle, n_middle)
113
+ # x.gsub!("_=", "=")
114
+ # x
115
+ # end
116
+
26
117
  class << self
27
118
 
28
119
  RANDOM_CHARS = [('A'..'H').to_a, ('J'..'N').to_a, ('P'..'T').to_a, ('W'..'Z').to_a, ('3'..'9').to_a].flatten
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mark_facets
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.9
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - markbates
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-25 00:00:00 -05:00
13
+ date: 2011-04-22 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- hash: 3474806802023863937
73
+ hash: 428702734687293533
74
74
  segments:
75
75
  - 0
76
76
  version: "0"
@@ -79,14 +79,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- hash: 3474806802023863937
82
+ hash: 428702734687293533
83
83
  segments:
84
84
  - 0
85
85
  version: "0"
86
86
  requirements: []
87
87
 
88
88
  rubyforge_project: magrathea
89
- rubygems_version: 1.5.0
89
+ rubygems_version: 1.6.2
90
90
  signing_key:
91
91
  specification_version: 3
92
92
  summary: mark_facets