Class: WikidataPositionHistory::Check::MissingFields

Inherits:
WikidataPositionHistory::Check show all
Defined in:
lib/wikidata_position_history/checks.rb

Overview

Does the Officeholder have all the properties we expect?

Instance Method Summary collapse

Methods inherited from WikidataPositionHistory::Check

#explanation, #initialize

Constructor Details

This class inherits a constructor from WikidataPositionHistory::Check

Instance Method Details

#expect_end_date?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/wikidata_position_history/checks.rb', line 74

def expect_end_date?
  later
end

#expect_next?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
# File 'lib/wikidata_position_history/checks.rb', line 85

def expect_next?
  return unless later
  return if later.officeholder.id == current.officeholder.id # sucessive terms by same person

  !current.acting?
end

#expect_prev?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/wikidata_position_history/checks.rb', line 78

def expect_prev?
  return unless earlier
  return if earlier.officeholder.id == current.officeholder.id # sucessive terms by same person

  !current.acting?
end

#expect_start_date?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/wikidata_position_history/checks.rb', line 70

def expect_start_date?
  true
end

#expectedObject



66
67
68
# File 'lib/wikidata_position_history/checks.rb', line 66

def expected
  field_map.keys.select { |field| send("expect_#{field}?") }
end

#field_mapObject



57
58
59
60
61
62
63
64
# File 'lib/wikidata_position_history/checks.rb', line 57

def field_map
  {
    start_date: 580,
    prev:       1365,
    end_date:   582,
    next:       1366,
  }
end

#headlineObject



45
46
47
# File 'lib/wikidata_position_history/checks.rb', line 45

def headline
  "Missing field#{missing.count > 1 ? 's' : ''}"
end

#missingObject



53
54
55
# File 'lib/wikidata_position_history/checks.rb', line 53

def missing
  expected.reject { |field| current.send(field) }
end

#possible_explanationObject



49
50
51
# File 'lib/wikidata_position_history/checks.rb', line 49

def possible_explanation
  "#{current.officeholder.qlink} is missing #{missing.map { |field| "{{P|#{field_map[field]}}}" }.join(', ')}"
end

#problem?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/wikidata_position_history/checks.rb', line 41

def problem?
  missing.any?
end