Class: Stupidedi::Reader::SegmentDict::NonEmpty

Inherits:
Stupidedi::Reader::SegmentDict show all
Defined in:
lib/stupidedi/reader/segment_dict.rb

Constant Summary

Constants inherited from Stupidedi::Reader::SegmentDict

Empty

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Stupidedi::Reader::SegmentDict

build, empty

Methods included from Inspect

#inspect

Constructor Details

#initialize(top, pop = SegmentDict.empty) ⇒ NonEmpty

Returns a new instance of NonEmpty.



43
44
45
# File 'lib/stupidedi/reader/segment_dict.rb', line 43

def initialize(top, pop = SegmentDict.empty)
  @top, @pop = top, pop
end

Instance Attribute Details

#popSegmentDict (readonly)

Returns:



41
42
43
# File 'lib/stupidedi/reader/segment_dict.rb', line 41

def pop
  @pop
end

#topObject (readonly)

Returns the value of attribute top.



38
39
40
# File 'lib/stupidedi/reader/segment_dict.rb', line 38

def top
  @top
end

Instance Method Details

#at(segment_id) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/stupidedi/reader/segment_dict.rb', line 62

def at(segment_id)
  if @top.defined_at?(segment_id)
    @top.at(segment_id)
  else
    @pop.at(segment_id)
  end
end

#copy(changes = {}) ⇒ SegmentDict

Returns:



48
49
50
51
52
# File 'lib/stupidedi/reader/segment_dict.rb', line 48

def copy(changes = {})
  NonEmpty.new \
    changes.fetch(:top, @top),
    changes.fetch(:pop, @pop)
end

#defined_at?(segment_id) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/stupidedi/reader/segment_dict.rb', line 70

def defined_at?(segment_id)
  @top.defined_at?(segment_id) or
  @pop.defined_at?(segment_id)
end

#empty?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/stupidedi/reader/segment_dict.rb', line 75

def empty?
  false
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stupidedi/reader/segment_dict.rb', line 80

def pretty_print(q)
  q.text "SegmentDict"
  q.group(2, "(", ")") do
    q.breakable ""

    node = self
    until node.empty?
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp node.top
      node = node.pop
    end
  end
end

#push(top) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/stupidedi/reader/segment_dict.rb', line 54

def push(top)
  if top.is_a?(Module)
    copy(:top => Constants.new(top), :pop => self)
  else
    copy(:top => top, :pop => self)
  end
end