Class: Locca::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/locca/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#langObject

Returns the value of attribute lang.



28
29
30
# File 'lib/locca/collection.rb', line 28

def lang
  @lang
end

#nameObject

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_keysObject



55
56
57
# File 'lib/locca/collection.rb', line 55

def all_keys
    return @items.keys
end

#countObject



79
80
81
# File 'lib/locca/collection.rb', line 79

def count
    return @items.count
end

#eachObject



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

Returns:

  • (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_commentsObject



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_eachObject



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_sObject



96
# File 'lib/locca/collection.rb', line 96

def to_s ; "<#{self.class}: lang = #{lang}, name = #{name}>" ; end

#translated?Boolean

Returns:

  • (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