Class: Locca::Collection
- Inherits:
-
Object
- Object
- Locca::Collection
- Defined in:
- lib/locca/collection.rb
Instance Attribute Summary collapse
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_item(item) ⇒ Object
- #all_keys ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(name = nil, lang = nil) ⇒ Collection
constructor
A new instance of Collection.
- #item_for_key(key) ⇒ Object
- #keys_without_comments ⇒ Object
- #remove_item_for_key(key) ⇒ Object
- #sorted_each ⇒ Object
- #to_s ⇒ Object
- #translated? ⇒ Boolean
Constructor Details
#initialize(name = nil, lang = nil) ⇒ Collection
Returns a new instance of Collection.
30 31 32 33 34 |
# File 'lib/locca/collection.rb', line 30 def initialize(name = nil, lang = nil) @name = name @lang = lang @items = {} end |
Instance Attribute Details
#lang ⇒ Object
Returns the value of attribute lang.
28 29 30 |
# File 'lib/locca/collection.rb', line 28 def lang @lang end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/locca/collection.rb', line 27 def name @name end |
Instance Method Details
#add_item(item) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/locca/collection.rb', line 36 def add_item(item) if !item || !item.key raise ArgumentError, 'item or item.key is nil' end @items[item.key] = item end |
#all_keys ⇒ Object
55 56 57 |
# File 'lib/locca/collection.rb', line 55 def all_keys return @items.keys end |
#count ⇒ Object
79 80 81 |
# File 'lib/locca/collection.rb', line 79 def count return @items.count end |
#each ⇒ Object
83 84 85 86 87 |
# File 'lib/locca/collection.rb', line 83 def each @items.each do |key, item| yield(item) end end |
#has_key?(key) ⇒ Boolean
51 52 53 |
# File 'lib/locca/collection.rb', line 51 def has_key?(key) return @items.has_key?(key) end |
#item_for_key(key) ⇒ Object
47 48 49 |
# File 'lib/locca/collection.rb', line 47 def item_for_key(key) return @items[key] end |
#keys_without_comments ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/locca/collection.rb', line 59 def keys_without_comments result = [] @items.each do |key, item| if item.comment == nil || item.comment.strip.length == 0 result.push(key) end end return result end |
#remove_item_for_key(key) ⇒ Object
43 44 45 |
# File 'lib/locca/collection.rb', line 43 def remove_item_for_key(key) return @items.delete(key) end |
#sorted_each ⇒ Object
89 90 91 92 93 94 |
# File 'lib/locca/collection.rb', line 89 def sorted_each sorted_keys = all_keys.sort(&:casecmp) sorted_keys.each do |key| yield(@items[key]) end end |
#to_s ⇒ Object
96 |
# File 'lib/locca/collection.rb', line 96 def to_s ; "<#{self.class}: lang = #{lang}, name = #{name}>" ; end |
#translated? ⇒ Boolean
69 70 71 72 73 74 75 76 77 |
# File 'lib/locca/collection.rb', line 69 def translated? @items.each do |key, item| if !item.translated? return false end end return true end |