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.



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

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

Instance Attribute Details

#popSegmentDict (readonly)

Returns:



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

def pop
  @pop
end

#topObject (readonly)

Returns the value of attribute top.



34
35
36
# File 'lib/stupidedi/reader/segment_dict.rb', line 34

def top
  @top
end

Instance Method Details

#at(segment_id) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/stupidedi/reader/segment_dict.rb', line 58

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:



44
45
46
47
48
# File 'lib/stupidedi/reader/segment_dict.rb', line 44

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

#defined_at?(segment_id) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/stupidedi/reader/segment_dict.rb', line 66

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  false
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/stupidedi/reader/segment_dict.rb', line 76

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



50
51
52
53
54
55
56
# File 'lib/stupidedi/reader/segment_dict.rb', line 50

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