Class: Interscript::Node::Item
- Inherits:
-
Interscript::Node
- Object
- Interscript::Node
- Interscript::Node::Item
- Defined in:
- lib/interscript/node/item.rb,
lib/interscript/visualize/nodes.rb
Direct Known Subclasses
Alias, Any, CaptureGroup, CaptureRef, Group, Repeat, Stage, String
Defined Under Namespace
Classes: Alias, Any, CaptureGroup, CaptureRef, Group, Maybe, MaybeSome, Repeat, Some, Stage, String
Instance Attribute Summary collapse
-
#item ⇒ Object
Returns the value of attribute item.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(item) ⇒ Item
constructor
A new instance of Item.
- #to_hash ⇒ Object
Constructor Details
#initialize(item) ⇒ Item
Returns a new instance of Item.
3 4 5 |
# File 'lib/interscript/node/item.rb', line 3 def initialize item raise NotImplementedError, "You can't construct a Node::Item directly" end |
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
2 3 4 |
# File 'lib/interscript/node/item.rb', line 2 def item @item end |
Class Method Details
.try_convert(i) ⇒ Object
43 44 45 46 47 |
# File 'lib/interscript/node/item.rb', line 43 def self.try_convert(i) i = Interscript::Node::Item::String.new(i) if i.class == ::String raise Interscript::MapLogicError, "Wrong type #{i.class}, expected I::Node::Item" unless Interscript::Node::Item === i i end |
Instance Method Details
#+(other) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/interscript/node/item.rb', line 7 def + other this = self this = this.children if Interscript::Node::Item::Group === this other = other.children if Interscript::Node::Item::Group === other this = Array(this) other = Array(other) this = this.map { |i| Interscript::Node::Item.try_convert(i) } other = other.map { |i| Interscript::Node::Item.try_convert(i) } middle = [] if Interscript::Node::Item::String === this.last && Interscript::Node::Item::String === other.first middle = [this.last + other.first] this = this[0..-2] other = this[1..-1] end g = Interscript::Node::Item::Group.new(*this, *middle, *other) g.verify! g end |
#==(other) ⇒ Object
39 40 41 |
# File 'lib/interscript/node/item.rb', line 39 def ==(other) super end |
#to_hash ⇒ Object
34 35 36 37 |
# File 'lib/interscript/node/item.rb', line 34 def to_hash { :class => self.class.to_s, :item => self.item } end |