Class: Stupidedi::Reader::Failure

Inherits:
Either::Failure show all
Includes:
Result
Defined in:
lib/stupidedi/reader/result.rb

Instance Attribute Summary collapse

Attributes inherited from Either::Failure

#reason

Instance Method Summary collapse

Methods included from Result

#column, failure, #line, #offset, #position, success

Methods inherited from Either::Failure

#defined?, #explain, #fetch, #flatmap, #inspect, #map, #or, #reject, #select, #tap

Methods inherited from Either

#defined?, #explain, failure, #fetch, #flatmap, #map, #or, #reject, #select, success

Constructor Details

#initialize(reason, remainder, fatal) ⇒ Failure

Returns a new instance of Failure.



119
120
121
122
# File 'lib/stupidedi/reader/result.rb', line 119

def initialize(reason, remainder, fatal)
  @reason, @remainder, @fatal =
    reason, remainder, fatal
end

Instance Attribute Details

#remainderObject (readonly)

Returns the value of attribute remainder.



117
118
119
# File 'lib/stupidedi/reader/result.rb', line 117

def remainder
  @remainder
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
# File 'lib/stupidedi/reader/result.rb', line 141

def ==(other)
  if other.is_a?(self.class)
    @reason == other.reason
  else
    @reason == other
  end
end

#copy(changes = {}) ⇒ Failure

Returns:



125
126
127
128
129
130
# File 'lib/stupidedi/reader/result.rb', line 125

def copy(changes = {})
  Failure.new \
    changes.fetch(:reason, @reason),
    changes.fetch(:remainder, @remainder),
    changes.fetch(:fatal, @fatal)
end

#fatalObject



136
137
138
# File 'lib/stupidedi/reader/result.rb', line 136

def fatal
  copy(:fatal => true)
end

#fatal?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/stupidedi/reader/result.rb', line 132

def fatal?
  @fatal
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/stupidedi/reader/result.rb', line 150

def pretty_print(q)
  q.text "Result.failure"
  q.group(2, "(", ")") do
    q.breakable ""
    q.pp @reason
    q.text ","
    q.breakable
    q.pp @remainder
    q.text ","
    q.breakable
    q.text "#{@fatal ? "" : "non-"}fatal"
  end
end