Class: Input::MultilineValue
- Inherits:
-
Object
- Object
- Input::MultilineValue
- Defined in:
- mygame/lib/sprite_kit/vendor/input.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #index(text) ⇒ Object
-
#initialize(text, word_wrap_chars, crlf_chars, w, font_style:) ⇒ MultilineValue
constructor
A new instance of MultilineValue.
-
#insert(from, to, text) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #length ⇒ Object
- #reflow(w, font_style) ⇒ Object
- #replace(text) ⇒ Object
- #rindex(text) ⇒ Object
- #slice(from, length = 1) ⇒ Object (also: #[])
- #to_s ⇒ Object
Constructor Details
#initialize(text, word_wrap_chars, crlf_chars, w, font_style:) ⇒ MultilineValue
Returns a new instance of MultilineValue.
156 157 158 159 160 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 156 def initialize(text, word_wrap_chars, crlf_chars, w, font_style:) @w = w @line_parser = LineParser.new(word_wrap_chars, crlf_chars, font_style: font_style) @lines = @line_parser.perform_word_wrap(text, @w) end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
154 155 156 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 154 def lines @lines end |
Instance Method Details
#empty? ⇒ Boolean
170 171 172 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 170 def empty? @lines.last.end == 0 end |
#index(text) ⇒ Object
185 186 187 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 185 def index(text) @lines.text.index(text) end |
#insert(from, to, text) ⇒ Object
rubocop:disable Metrics/AbcSize
174 175 176 177 178 179 180 181 182 183 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 174 def insert(from, to, text) # rubocop:disable Metrics/AbcSize modified_lines = @lines.modified(from, to) original_value = modified_lines.text first_modified_line = modified_lines.first original_index = first_modified_line.start modified_value = original_value[0, from - original_index].to_s + text + original_value[to - original_index, original_value.length].to_s new_lines = @line_parser.perform_word_wrap(modified_value, @w, first_modified_line.number, original_index) @lines.replace(modified_lines, new_lines) end |
#length ⇒ Object
166 167 168 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 166 def length @lines.last.end end |
#reflow(w, font_style) ⇒ Object
202 203 204 205 206 207 208 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 202 def reflow(w, font_style) return if @w == w && @font_style == font_style @w = w @font_style = font_style @lines = @line_parser.perform_word_wrap(@lines.text, w, 0, 0, font_style) end |
#replace(text) ⇒ Object
198 199 200 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 198 def replace(text) @lines = @line_parser.perform_word_wrap(text, @w) end |
#rindex(text) ⇒ Object
189 190 191 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 189 def rindex(text) @lines.text.rindex(text) end |
#slice(from, length = 1) ⇒ Object Also known as: []
193 194 195 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 193 def slice(from, length = 1) @lines.text.slice(from, length) end |
#to_s ⇒ Object
162 163 164 |
# File 'mygame/lib/sprite_kit/vendor/input.rb', line 162 def to_s @lines.text end |