Class: LanguageCards::Comparator
- Inherits:
-
Object
- Object
- LanguageCards::Comparator
- Defined in:
- lib/language_cards/comparator.rb
Instance Method Summary collapse
- #given(key, value) ⇒ Object
-
#initialize(mapping_key, mapping, collection) ⇒ Comparator
constructor
A new instance of Comparator.
- #mapped_as ⇒ Object
- #match?(input, comp_bitz) ⇒ Boolean
Constructor Details
#initialize(mapping_key, mapping, collection) ⇒ Comparator
Returns a new instance of Comparator.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/language_cards/comparator.rb', line 5 def initialize mapping_key, mapping, collection ## # @title should be a hash like {"Romaji"=>"Katakana"} # @mapping should be an array like [:k, :v] raise I18n.t('Error.MappingNotFound') unless mapping.has_key? mapping_key begin @mapped_as, @mapping = mapping[mapping_key].reduce rescue LocalJumpError raise I18n.t('Errors.InvalidMapping') end @collection = collection end |
Instance Method Details
#given(key, value) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/language_cards/comparator.rb', line 28 def given key, value CompBitz.new( display: choose_display(key, value), collection: @collection, expected: choose_expected(key, value), value: value, mapping: @mapping.first ) end |
#mapped_as ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/language_cards/comparator.rb', line 19 def mapped_as case @mapping.first when :k @mapped_as.keys else @mapped_as.values end end |
#match?(input, comp_bitz) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/language_cards/comparator.rb', line 38 def match? input, comp_bitz case comp_bitz.mapping when :k comp_bitz.value == comp_bitz.collection[input] when :v comp_bitz.value == input end end |