Class: SuperDiff::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/line.rb

Constant Summary collapse

ICONS =
{ delete: "-", insert: "+", noop: " " }.freeze
COLORS =
{ insert: :actual, delete: :expected, noop: :plain }.freeze

Instance Method Summary collapse

Instance Method Details

#as_elidedObject



51
52
53
# File 'lib/super_diff/line.rb', line 51

def as_elided
  clone_with(elided: true)
end

#clone_with(overrides = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/super_diff/line.rb', line 24

def clone_with(overrides = {})
  self.class.new(
    type: type,
    indentation_level: indentation_level,
    prefix: prefix,
    value: value,
    add_comma: add_comma?,
    children: children,
    elided: elided?,
    collection_bookend: collection_bookend,
    complete_bookend: complete_bookend,
    **overrides
  )
end

#closes_collection?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/super_diff/line.rb', line 75

def closes_collection?
  collection_bookend == :close
end

#colorObject



43
44
45
# File 'lib/super_diff/line.rb', line 43

def color
  COLORS.fetch(type)
end

#complete_bookend?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/super_diff/line.rb', line 79

def complete_bookend?
  complete_bookend != nil
end

#iconObject



39
40
41
# File 'lib/super_diff/line.rb', line 39

def icon
  ICONS.fetch(type)
end

#opens_collection?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/super_diff/line.rb', line 71

def opens_collection?
  collection_bookend == :open
end

#prefixed_with(prefix) ⇒ Object



63
64
65
# File 'lib/super_diff/line.rb', line 63

def prefixed_with(prefix)
  clone_with(prefix: prefix + self.prefix)
end

#with_commaObject



47
48
49
# File 'lib/super_diff/line.rb', line 47

def with_comma
  clone_with(add_comma: true)
end

#with_complete_bookend(complete_bookend) ⇒ Object



67
68
69
# File 'lib/super_diff/line.rb', line 67

def with_complete_bookend(complete_bookend)
  clone_with(complete_bookend: complete_bookend)
end

#with_value_appended(suffix) ⇒ Object



59
60
61
# File 'lib/super_diff/line.rb', line 59

def with_value_appended(suffix)
  clone_with(value: value + suffix)
end

#with_value_prepended(prelude) ⇒ Object



55
56
57
# File 'lib/super_diff/line.rb', line 55

def with_value_prepended(prelude)
  clone_with(value: prelude + value)
end