Sha256: 3f00edbc4b4bbeafeece13dfab64451b6e27c3608712631b825cc68e57c9a564
Contents?: true
Size: 955 Bytes
Versions: 3
Compression:
Stored size: 955 Bytes
Contents
module GalaxyConverter module Constraint extend self def call(value) return if value.empty? violations.any? { |violation| value.index(violation) } end private def violations @violations ||= repetitions + subtractions end private def repetitions too_many_repetitions + unrepeatable end private def too_many_repetitions %w[I X C M].map { |c| c * 4 } end private def unrepeatable %w[D L V].map { |c| c * 2 } end private def subtractions repeated_sub + wrong_sub end private def repeated_sub %w[V X].map { |c| "II#{c}"} + %w[L C].map { |c| "XX#{c}"} + %w[D M].map { |c| "CC#{c}"} end private def wrong_sub %w[L C D M].map { |c| "I#{c}" } + %w[D M].map { |c| "X#{c}" } + %w[X L C D M].map { |c| "V#{c}" } + %w[C D M].map { |c| "L#{c}"} + %w[M].map { |c| "D#{c}" } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
galaxy_converter-3.1.2 | lib/galaxy_converter/constraint.rb |
galaxy_converter-3.1.1 | lib/galaxy_converter/constraint.rb |
galaxy_converter-3.0.1 | lib/galaxy_converter/constraint.rb |