Class: LanguageCards::Mappings
- Inherits:
-
Object
- Object
- LanguageCards::Mappings
- Defined in:
- lib/language_cards/mapping.rb
Defined Under Namespace
Classes: InvalidMapping
Instance Method Summary collapse
- #[](key) ⇒ Object
- #classes(s = nil) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(mapping, collection = nil) ⇒ Mappings
constructor
A new instance of Mappings.
- #inspect ⇒ Object
- #keys ⇒ Object
-
#order(key) ⇒ Object
what was my intention in design here?.
- #select_mapping(string) ⇒ Object
Constructor Details
#initialize(mapping, collection = nil) ⇒ Mappings
Returns a new instance of Mappings.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/language_cards/mapping.rb', line 3 def initialize mapping, collection=nil @collection = collection @mappings = {} mapping.each do |h| index = h.delete("index") begin a,b = h.reduce rescue LocalJumpError raise InvalidMapping end a = I18n.t "LanguageName.#{a}" b = I18n.t "LanguageName.#{b}" @mappings["#{a} => #{b}"] = { h => index } end end |
Instance Method Details
#[](key) ⇒ Object
32 33 34 |
# File 'lib/language_cards/mapping.rb', line 32 def [] key @mappings[key] end |
#classes(s = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/language_cards/mapping.rb', line 26 def classes s=nil keys.map do |names| [s, names].compact.join(JOIN) end end |
#has_key?(key) ⇒ Boolean
40 41 42 |
# File 'lib/language_cards/mapping.rb', line 40 def has_key? key @mappings.has_key? key end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/language_cards/mapping.rb', line 48 def inspect @mappings.keys end |
#keys ⇒ Object
44 45 46 |
# File 'lib/language_cards/mapping.rb', line 44 def keys @mappings.keys end |
#order(key) ⇒ Object
what was my intention in design here?
36 37 38 |
# File 'lib/language_cards/mapping.rb', line 36 def order key # what was my intention in design here? self[key].values.flatten end |
#select_mapping(string) ⇒ Object
22 23 24 |
# File 'lib/language_cards/mapping.rb', line 22 def select_mapping string Comparator.new string, self, @collection end |