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.



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

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

Instance Attribute Details

#remainderObject (readonly)

Returns the value of attribute remainder.



113
114
115
# File 'lib/stupidedi/reader/result.rb', line 113

def remainder
  @remainder
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
141
142
143
# File 'lib/stupidedi/reader/result.rb', line 137

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

#copy(changes = {}) ⇒ Failure

Returns:



121
122
123
124
125
126
# File 'lib/stupidedi/reader/result.rb', line 121

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

#fatalObject



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

def fatal
  copy(:fatal => true)
end

#fatal?Boolean

Returns:

  • (Boolean)


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

def fatal?
  @fatal
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/stupidedi/reader/result.rb', line 146

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