Class: Twine::StringsRow

Inherits:
Object
  • Object
show all
Defined in:
lib/twine/stringsfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ StringsRow

Returns a new instance of StringsRow.



18
19
20
21
22
23
# File 'lib/twine/stringsfile.rb', line 18

def initialize(key)
  @key = key
  @comment = nil
  @tags = nil
  @translations = {}
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



14
15
16
# File 'lib/twine/stringsfile.rb', line 14

def comment
  @comment
end

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/twine/stringsfile.rb', line 13

def key
  @key
end

#tagsObject

Returns the value of attribute tags.



15
16
17
# File 'lib/twine/stringsfile.rb', line 15

def tags
  @tags
end

#translationsObject (readonly)

Returns the value of attribute translations.



16
17
18
# File 'lib/twine/stringsfile.rb', line 16

def translations
  @translations
end

Instance Method Details

#matches_tags?(tags, include_untagged) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twine/stringsfile.rb', line 25

def matches_tags?(tags, include_untagged)
  if tags == nil || tags.length == 0
    # The user did not specify any tags. Everything passes.
    return true
  elsif @tags == nil || @tags.length == 0
    # This row has no tags.
    return (include_untagged) ? true : false
  else
    tags.each do |tag|
      if @tags.include? tag
        return true
      end
    end
  end

  return false
end

#translated_string_for_lang(lang, default_lang = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twine/stringsfile.rb', line 43

def translated_string_for_lang(lang, default_lang=nil)
  if @translations[lang]
    return @translations[lang]
  elsif default_lang.respond_to?("each")
    default_lang.each do |def_lang|
      if @translations[def_lang]
        return @translations[def_lang]
      end
    end
    return nil
  else
    return @translations[default_lang]
  end
end