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.



20
21
22
23
24
25
# File 'lib/twine/stringsfile.rb', line 20

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

#referenceObject

Returns the value of attribute reference.



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

def reference
  @reference
end

#reference_keyObject

Returns the value of attribute reference_key.



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

def reference_key
  @reference_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)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/twine/stringsfile.rb', line 35

def matches_tags?(tags, include_untagged)
  if tags == nil || tags.empty?
    # The user did not specify any tags. Everything passes.
    return true
  elsif @tags == nil
    # This row has no tags.
    return reference ? reference.matches_tags?(tags, include_untagged) : include_untagged
  elsif @tags.empty?
    return include_untagged
  else
    return !(tags & @tags).empty?
  end

  return false
end

#raw_commentObject



31
32
33
# File 'lib/twine/stringsfile.rb', line 31

def raw_comment
  @comment
end

#translated_string_for_lang(lang) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/twine/stringsfile.rb', line 51

def translated_string_for_lang(lang)
  translation = [lang].flatten.map { |l| @translations[l] }.first

  translation = reference.translated_string_for_lang(lang) if translation.nil? && reference

  return translation
end