Class: Stupidedi::Reader::Success

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Result

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

Methods inherited from Either::Success

#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(value, remainder) ⇒ Success

Returns a new instance of Success.



62
63
64
# File 'lib/stupidedi/reader/result.rb', line 62

def initialize(value, remainder)
  @value, @remainder = value, remainder
end

Instance Attribute Details

#remainderObject (readonly)

Returns the value of attribute remainder.



60
61
62
# File 'lib/stupidedi/reader/result.rb', line 60

def remainder
  @remainder
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/stupidedi/reader/result.rb', line 78

def ==(other)
  if other.is_a?(self.class)
    @value == other.value and @remainder == other.remainder
  else
    @value == other
  end
end

#blank?Boolean

Override Enumerable#blank? since we’re not really Enumerable

Returns:

  • (Boolean)


99
100
101
# File 'lib/stupidedi/reader/result.rb', line 99

def blank?
  false
end

#copy(changes = {}) ⇒ Success

Returns:



67
68
69
70
71
# File 'lib/stupidedi/reader/result.rb', line 67

def copy(changes = {})
  Success.new \
    changes.fetch(:value, @value),
    changes.fetch(:remainder, @remainder)
end

#fatal?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/stupidedi/reader/result.rb', line 73

def fatal?
  false
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



87
88
89
90
91
92
93
94
95
96
# File 'lib/stupidedi/reader/result.rb', line 87

def pretty_print(q)
  q.text "Result.success"
  q.group(2, "(", ")") do
    q.breakable ""
    q.pp @value
    q.text ","
    q.breakable
    q.pp @remainder
  end
end