Class: Interscript::Node::Item::String
- Inherits:
-
Interscript::Node::Item
- Object
- Interscript::Node
- Interscript::Node::Item
- Interscript::Node::Item::String
- Defined in:
- lib/interscript/visualize/nodes.rb,
lib/interscript/node/item/string.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Attributes inherited from Interscript::Node::Item
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #downcase ⇒ Object
- #first_string ⇒ Object (also: #nth_string)
-
#initialize(data) ⇒ String
constructor
A new instance of String.
- #inspect ⇒ Object
- #max_length ⇒ Object
- #to_hash ⇒ Object
- #to_html(_) ⇒ Object
- #upcase ⇒ Object
Methods inherited from Interscript::Node::Item
Constructor Details
#initialize(data) ⇒ String
Returns a new instance of String.
3 4 5 |
# File 'lib/interscript/node/item/string.rb', line 3 def initialize data self.data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
2 3 4 |
# File 'lib/interscript/node/item/string.rb', line 2 def data @data end |
Instance Method Details
#+(other) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/interscript/node/item/string.rb', line 25 def + other if self.data == "" Interscript::Node::Item.try_convert(other) elsif Interscript::Node::Item::String === self && (Interscript::Node::Item::String === other || ::String === other) other = Interscript::Node::Item.try_convert(other) Interscript::Node::Item::String.new(self.data + other.data) else super end end |
#==(other) ⇒ Object
39 40 41 |
# File 'lib/interscript/node/item/string.rb', line 39 def ==(other) super && self.data == other.data end |
#downcase ⇒ Object
20 |
# File 'lib/interscript/node/item/string.rb', line 20 def downcase; self.dup.tap { |i| i.data = i.data.downcase }; end |
#first_string ⇒ Object Also known as: nth_string
16 17 18 |
# File 'lib/interscript/node/item/string.rb', line 16 def first_string self.data end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/interscript/node/item/string.rb', line 43 def inspect @data.inspect end |
#max_length ⇒ Object
12 13 14 |
# File 'lib/interscript/node/item/string.rb', line 12 def max_length self.data.length end |
#to_hash ⇒ Object
7 8 9 10 |
# File 'lib/interscript/node/item/string.rb', line 7 def to_hash { :class => self.class.to_s, :data => self.data } end |
#to_html(_) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/interscript/visualize/nodes.rb', line 78 def to_html(_) out = "" self.data.each_char do |i| out << "<ruby>" out << "<kbd>#{h i}</kbd>" out << "<rt>#{"%04x" % i.ord}</rt>" out << "</ruby>" end out end |
#upcase ⇒ Object
21 |
# File 'lib/interscript/node/item/string.rb', line 21 def upcase; self.dup.tap { |i| i.data = i.data.upcase }; end |