Class: Interscript::Node::Item::Repeat

Inherits:
Interscript::Node::Item show all
Defined in:
lib/interscript/visualize/nodes.rb,
lib/interscript/node/item/repeat.rb

Direct Known Subclasses

Maybe, MaybeSome, Some

Instance Attribute Summary collapse

Attributes inherited from Interscript::Node::Item

#item

Instance Method Summary collapse

Methods inherited from Interscript::Node::Item

#+, try_convert

Constructor Details

#initialize(data) ⇒ Repeat

Returns a new instance of Repeat.



3
4
5
6
# File 'lib/interscript/node/item/repeat.rb', line 3

def initialize data
  data = Interscript::Node::Item.try_convert(data)
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



2
3
4
# File 'lib/interscript/node/item/repeat.rb', line 2

def data
  @data
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/interscript/node/item/repeat.rb', line 25

def ==(other)
  super && self.data == other.data
end

#first_stringObject



8
9
10
# File 'lib/interscript/node/item/repeat.rb', line 8

def first_string
  data.first_string
end

#inspectObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/interscript/node/item/repeat.rb', line 29

def inspect
  str = case self
  when Interscript::Node::Item::Maybe
    "maybe"
  when Interscript::Node::Item::MaybeSome
    "maybe_some"
  when Interscript::Node::Item::Some
    "some"
  end
  "#{str}(#{@data.inspect})"
end

#max_lengthObject



16
17
18
# File 'lib/interscript/node/item/repeat.rb', line 16

def max_length
  data.max_length
end

#nth_stringObject



12
13
14
# File 'lib/interscript/node/item/repeat.rb', line 12

def nth_string
  data.nth_string
end

#to_hashObject



20
21
22
23
# File 'lib/interscript/node/item/repeat.rb', line 20

def to_hash
  { :class => self.class.to_s,
    :data => self.data.to_hash }
end

#to_html(doc) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/interscript/visualize/nodes.rb', line 64

def to_html(doc)
  str = case self
  when Interscript::Node::Item::Maybe
    "zero or one "
  when Interscript::Node::Item::MaybeSome
    "zero or more of "
  when Interscript::Node::Item::Some
    "one or more of "
  end
  "<nobr>#{str}(</nobr>#{@data.to_html(doc)})"
end