Module: Cheri::Java::Builder::Util
- Defined in:
- lib/cheri/java/builder/util.rb
Constant Summary collapse
- S =
:stopdoc:
'set'
- G =
'get'
- I =
'is'
- U =
'_'
Class Method Summary collapse
- .acc?(s) ⇒ Boolean (also: is_accessor)
-
.cc(sym) ⇒ Object
(also: camel_case, upper_camel_case)
call-seq: Util.cc(‘my_string’) -> ‘MyString’ Util.camel_case(‘my_string’) -> ‘MyString’ Util.upper_camel_case(‘my_string’) -> ‘MyString’ create upper-camel-case string.
-
.const?(s) ⇒ Boolean
(also: is_constant)
symbols are considered constants if the first character is capitalized.
- .getter(y) ⇒ Object (also: make_getter)
- .getter?(s) ⇒ Boolean (also: is_getter)
- .iser(y) ⇒ Object (also: make_iser)
- .iser?(s) ⇒ Boolean (also: is_iser)
-
.lcc(str) ⇒ Object
(also: lower_camel_case)
call-seq: Util.lcc(‘my_string’) -> ‘myString’ Util.lower_camel_case(‘my_string’) -> ‘myString’.
- .setter(y) ⇒ Object (also: make_setter)
- .setter?(s) ⇒ Boolean (also: is_setter)
-
.uf(y) ⇒ Object
(also: upper_first)
call-seq: Util.uf(‘str’) -> ‘Str’ Util.upper_first(‘str’) -> ‘Str’ Like String#capitalize, but only alters the first character, so Util.upper_first(‘abCdeF’) -> ‘AbCdeF’.
Class Method Details
.acc?(s) ⇒ Boolean Also known as: is_accessor
96 97 98 |
# File 'lib/cheri/java/builder/util.rb', line 96 def acc?(s) (c = (s = s.to_s)[-1]) == ?= || c == ?? || s.rindex(G,0) || s.rindex(S,0) || s.rindex(I,0) end |
.cc(sym) ⇒ Object Also known as: camel_case, upper_camel_case
call-seq:
Util.cc('my_string') -> 'MyString'
Util.camel_case('my_string') -> 'MyString'
Util.upper_camel_case('my_string') -> 'MyString'
create upper-camel-case string
57 58 59 60 61 62 63 64 65 |
# File 'lib/cheri/java/builder/util.rb', line 57 def cc(sym) s = String === sym ? sym.dup : sym.to_s if s.index(?_) s.split(U).collect do |n| uf(n); end.join else # preserve existing camel-case, just force first char to upper uf(s) end end |
.const?(s) ⇒ Boolean Also known as: is_constant
symbols are considered constants if the first character is capitalized
118 119 120 |
# File 'lib/cheri/java/builder/util.rb', line 118 def const?(s) (c = s.to_s[0]) >= ?A && c <= ?Z end |
.getter(y) ⇒ Object Also known as: make_getter
106 107 108 |
# File 'lib/cheri/java/builder/util.rb', line 106 def getter(y) :"get#{cc(y)}" end |
.getter?(s) ⇒ Boolean Also known as: is_getter
86 87 88 |
# File 'lib/cheri/java/builder/util.rb', line 86 def getter?(s) s.to_s.rindex(G,0) end |
.iser(y) ⇒ Object Also known as: make_iser
111 112 113 |
# File 'lib/cheri/java/builder/util.rb', line 111 def iser(y) :"is#{cc(y)}" end |
.iser?(s) ⇒ Boolean Also known as: is_iser
91 92 93 |
# File 'lib/cheri/java/builder/util.rb', line 91 def iser?(s) (s = s.to_s).rindex(I,0) || ?? == s[-1] end |
.lcc(str) ⇒ Object Also known as: lower_camel_case
call-seq:
Util.lcc('my_string') -> 'myString'
Util.lower_camel_case('my_string') -> 'myString'
73 74 75 76 77 78 |
# File 'lib/cheri/java/builder/util.rb', line 73 def lcc(str) s = String === str ? str.dup : str.to_s # get lower-camel-case method name a = s.split(U) a.each_index do |i| a[i].capitalize! if i > 0; end.join end |
.setter(y) ⇒ Object Also known as: make_setter
101 102 103 |
# File 'lib/cheri/java/builder/util.rb', line 101 def setter(y) :"set#{cc(y)}" end |
.setter?(s) ⇒ Boolean Also known as: is_setter
81 82 83 |
# File 'lib/cheri/java/builder/util.rb', line 81 def setter?(s) s.to_s.rindex(S,0) end |
.uf(y) ⇒ Object Also known as: upper_first
call-seq:
Util.uf('str') -> 'Str'
Util.upper_first('str') -> 'Str'
Like String#capitalize, but only alters the first character, so Util.upper_first(‘abCdeF’) -> ‘AbCdeF’.
44 45 46 47 48 |
# File 'lib/cheri/java/builder/util.rb', line 44 def uf(y) s = y.to_s s[0] = s[0,1].upcase[0] unless s.empty? s end |