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.



58
59
60
# File 'lib/stupidedi/reader/result.rb', line 58

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

Instance Attribute Details

#remainderObject (readonly)

Returns the value of attribute remainder.



56
57
58
# File 'lib/stupidedi/reader/result.rb', line 56

def remainder
  @remainder
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/stupidedi/reader/result.rb', line 74

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)


95
96
97
# File 'lib/stupidedi/reader/result.rb', line 95

def blank?
  false
end

#copy(changes = {}) ⇒ Success

Returns:



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

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

#fatal?Boolean

Returns:

  • (Boolean)


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

def fatal?
  false
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



83
84
85
86
87
88
89
90
91
92
# File 'lib/stupidedi/reader/result.rb', line 83

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