Class: Insika::Refinement::Candidate

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/refinement/candidate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#droppedObject (readonly)

Returns the value of attribute dropped

Returns:

  • (Object)

    the current value of dropped



48
49
50
# File 'lib/insika/refinement/candidate.rb', line 48

def dropped
  @dropped
end

#editsObject (readonly)

Returns the value of attribute edits

Returns:

  • (Object)

    the current value of edits



48
49
50
# File 'lib/insika/refinement/candidate.rb', line 48

def edits
  @edits
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



48
49
50
# File 'lib/insika/refinement/candidate.rb', line 48

def id
  @id
end

#proposerObject (readonly)

Returns the value of attribute proposer

Returns:

  • (Object)

    the current value of proposer



48
49
50
# File 'lib/insika/refinement/candidate.rb', line 48

def proposer
  @proposer
end

#rationaleObject (readonly)

Returns the value of attribute rationale

Returns:

  • (Object)

    the current value of rationale



48
49
50
# File 'lib/insika/refinement/candidate.rb', line 48

def rationale
  @rationale
end

Instance Method Details

#apply(contents) ⇒ Object

name => new content, for the files this candidate touches. Edits to the same file compose in order, so two edits to TOOLS.md both land.



54
55
56
57
58
59
60
# File 'lib/insika/refinement/candidate.rb', line 54

def apply(contents)
  edits.each_with_object({}) do |edit, acc|
    current = acc[edit.file] || contents[edit.file]
    applied = edit.apply_to(current)
    acc[edit.file] = applied unless applied.nil?
  end
end

#empty?Boolean

Returns:

  • (Boolean)


49
# File 'lib/insika/refinement/candidate.rb', line 49

def empty? = edits.empty?

#filesObject



50
# File 'lib/insika/refinement/candidate.rb', line 50

def files = edits.map(&:file).uniq

#to_hObject



62
63
# File 'lib/insika/refinement/candidate.rb', line 62

def to_h = { "id" => id, "proposer" => proposer, "rationale" => rationale,
"edits" => edits.map(&:to_h), "dropped" => dropped.map(&:to_h) }