Class: Code::Object::String
Constant Summary
Constants inherited
from Code::Object
NUMBER_CLASSES
Instance Attribute Summary
#methods, #raw
Instance Method Summary
collapse
code_new, #code_new, maybe, #name, repeat, |
#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_compare, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_falsy?, #code_fetch, code_fetch, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_inclusive_range, #code_less, #code_less_or_equal, #code_methods, #code_name, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_self, #code_set, code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ String
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/code/object/string.rb', line 6
def initialize(*args, **_kargs, &_block)
self.raw =
if args.first.is_an?(Class)
args.first.raw.name
elsif args.first.is_an?(Object)
args.first.raw.to_s
elsif args.first.is_a?(::Class)
args.first.name
elsif args.first
args.first.to_s
else
""
end
end
|
Instance Method Details
#call(**args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/code/object/string.rb', line 21
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
code_arguments = args.fetch(:arguments, List.new).to_code
globals = multi_fetch(args, *GLOBALS)
code_value = code_arguments.code_first
case code_operator.to_s
when "&", "to_function"
sig(args)
code_to_function(**globals)
when "*"
sig(args) { Integer | Decimal }
code_multiplication(code_value)
when "+"
sig(args) { Object }
code_plus(code_value)
when "downcase"
sig(args)
code_downcase
when "include?"
sig(args) { String }
code_include?(code_value)
when "starts_with?"
sig(args) { String }
code_starts_with?(code_value)
when "start_with?"
sig(args) { String }
code_start_with?(code_value)
when "ends_with?"
sig(args) { String }
code_ends_with?(code_value)
when "end_with?"
sig(args) { String }
code_end_with?(code_value)
when "first"
sig(args) { Integer.maybe }
code_first(code_value)
when "reverse"
sig(args)
code_reverse
when "parameterize"
sig(args)
code_parameterize
when "substitute"
sig(args) { [String, String.maybe] }
code_substitute(*code_arguments.raw)
when "upcase"
sig(args)
code_upcase
when "size"
sig(args)
code_size
when "strip"
sig(args)
code_strip
when "split"
sig(args) { String }
code_split(code_value)
else
super
end
end
|
#code_downcase ⇒ Object
84
85
86
|
# File 'lib/code/object/string.rb', line 84
def code_downcase
String.new(raw.downcase)
end
|
#code_end_with?(value) ⇒ Boolean
111
112
113
114
|
# File 'lib/code/object/string.rb', line 111
def code_end_with?(value)
code_value = value.to_code
Boolean.new(raw.end_with?(code_value.raw))
end
|
#code_ends_with?(value) ⇒ Boolean
116
117
118
|
# File 'lib/code/object/string.rb', line 116
def code_ends_with?(value)
code_end_with?(value)
end
|
#code_first(n = nil) ⇒ Object
148
149
150
151
152
|
# File 'lib/code/object/string.rb', line 148
def code_first(n = nil)
code_n = n.to_code
code_n = Integer.new(1) if code_n.nothing?
String.new(raw.first(code_n.raw))
end
|
#code_include?(value) ⇒ Boolean
92
93
94
95
|
# File 'lib/code/object/string.rb', line 92
def code_include?(value)
code_value = value.to_code
Boolean.new(raw.include?(code_value.raw))
end
|
#code_inspect ⇒ Object
133
134
135
|
# File 'lib/code/object/string.rb', line 133
def code_inspect
String.new(raw.inspect)
end
|
#code_multiplication(other) ⇒ Object
97
98
99
100
|
# File 'lib/code/object/string.rb', line 97
def code_multiplication(other)
code_other = other.to_code
String.new(raw * code_other.raw)
end
|
#code_parameterize ⇒ Object
137
138
139
|
# File 'lib/code/object/string.rb', line 137
def code_parameterize
String.new(raw.parameterize)
end
|
#code_plus(other) ⇒ Object
120
121
122
123
|
# File 'lib/code/object/string.rb', line 120
def code_plus(other)
code_other = other.to_code
String.new(raw + code_other.to_s)
end
|
#code_reverse ⇒ Object
125
126
127
|
# File 'lib/code/object/string.rb', line 125
def code_reverse
String.new(raw.reverse)
end
|
#code_size ⇒ Object
154
155
156
|
# File 'lib/code/object/string.rb', line 154
def code_size
Integer.new(raw.size)
end
|
#code_split(value) ⇒ Object
162
163
164
165
166
|
# File 'lib/code/object/string.rb', line 162
def code_split(value)
code_value = value.to_code
List.new(raw.split(code_value.to_s))
end
|
#code_start_with?(value) ⇒ Boolean
107
108
109
|
# File 'lib/code/object/string.rb', line 107
def code_start_with?(value)
code_starts_with?(value)
end
|
#code_starts_with?(value) ⇒ Boolean
102
103
104
105
|
# File 'lib/code/object/string.rb', line 102
def code_starts_with?(value)
code_value = value.to_code
Boolean.new(raw.start_with?(code_value.raw))
end
|
#code_strip ⇒ Object
158
159
160
|
# File 'lib/code/object/string.rb', line 158
def code_strip
String.new(raw.strip)
end
|
#code_substitute(from = nil, to = nil) ⇒ Object
141
142
143
144
145
146
|
# File 'lib/code/object/string.rb', line 141
def code_substitute(from = nil, to = nil)
code_from = from.to_code
code_to = to.to_code
String.new(raw.gsub(code_from.to_s, code_to.to_s))
end
|
#code_to_function(**_globals) ⇒ Object
129
130
131
|
# File 'lib/code/object/string.rb', line 129
def code_to_function(**_globals)
Function.new([{ name: "_" }], "_.#{raw}")
end
|
#code_upcase ⇒ Object
88
89
90
|
# File 'lib/code/object/string.rb', line 88
def code_upcase
String.new(raw.upcase)
end
|
168
169
170
|
# File 'lib/code/object/string.rb', line 168
def present?
raw.present?
end
|